編寫Service文件
新建一個(gè)php文件,命名為EmployeeService.php。首先寫上這一句,include必要的支持代碼:
以下為引用的內(nèi)容: require_once 'MSAjaxService.php'; |
然后定義一個(gè)Employee類。四個(gè)屬性一目了然,不用多說:
以下為引用的內(nèi)容: function __construct($id, $name, $email, $salary) |
接下來是EmployeeService類,繼承與MSAjaxService.php中的MSAjaxService基類。其中定義一個(gè)方法,用來返回一個(gè)Employee對(duì)象:
以下為引用的內(nèi)容: class EmployeeService extends MSAjaxService { function GetEmployee() { return new Employee(12345, "Dflying Chen", "Dflying@some.com", 1000); } } |
然后新建一個(gè)EmployeeService的實(shí)例,并且調(diào)用基類的ProcessRequest()方法,處理該請(qǐng)求:
以下為引用的內(nèi)容: $theService = new EmployeeService(); $theService->ProcessRequest(); |
大功告成!
請(qǐng)作者聯(lián)系本站,及時(shí)附注您的姓名。聯(lián)系郵箱:CuoXIn#vip.qq.com(把#改為@)。
新聞熱點(diǎn)
疑難解答
圖片精選