字段校验-用于进入数据库的字段映射。在Service中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $field | Array | 是 | 可信任字段 array(array('field', 'int')) |
| $data | Array | 是 | 传入的参数 |
public function test() {
$field = array(
array('username', ''),
array('age', 'int'),
array('password', '')
);
$data = array('username' => 'init', 'age' => 10, 'password' => '123456');
$result = $this->service->parse_data($field, $data);
$this->getTestDao()->test($result);
}
Service经常会有很多复杂的验证情况,需要传递给Controller,可以通过return_msg返回一个结构体。在Service中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $status | Bool | 是 | 状态,true|false |
| $msg | String | 是 | 提示信息 |
| $data | Array | 是 | 传递的参数 |
class testService extends Service {
public function test() {
return $this->service->return_msg(0, '访问错误', '');
}
/**
* @return testDao
*/
private function getTestDao() {
return InitPHP::getDao('test', 'test');
}
/**
* @return testaDao
*/
private function getTestaDao() {
return InitPHP::getDao('testa', 'test');
}
}