|
<p><strong>编写Service文件</strong><br /><br />新建一个php文件,命名为EmployeeService.php。首先写上这一句,include必要的支持代码: <br /><br />require_once 'MSAjaxService.php'; <br /><br /><br />然后定义一个Employee类。四个属性一目了然,不用多说: <br /><br />class Employee <br />{ <br />public $Id; <br />public $Name; <br />public $Email; <br />public $Salary; <br /><br />function __construct($id, $name, $email, $salary) <br />{ <br />$this->Id = $id; <br />$this->Name = $name; <br />$this->Email = $email; <br />$this->Salary= $salary; <br />} <br />} <br /><br /><br />接下来是EmployeeService类,继承与MSAjaxService.php中的MSAjaxService基类。其中定义一个方法,用来返回一个Employee对象: <br /><br />class EmployeeService extends MSAjaxService <br />{ <br />function GetEmployee() <br />{ <br />return new Employee(12345, "Dflying Chen", "Dflying@some.com", 1000); <br />} <br />} <br /><br /><br />然后新建一个EmployeeService的实例,并且调用基类的ProcessRequest()方法,处理该请求: <br /><br />$theService = new EmployeeService(); <br />$theService-> rocessRequest(); <br /><br /><br />大功告成! <br /></p> |
|