我已经将REST项目用于REST API。当我从数据库中获取结果时,值的数据类型是错误的。我也定义了这个方案,但不确定什么是错的。以下是我的代码:
控制器:
public function view() {
$success = false;
$model = $this->model;
$data = $model::find('first', array(
'conditions'=> array('id' => $this->request->id)
)
);
if($data){
$success = true;
$data = $data->to('array');
}
return compact('data','success');
}
型号:
class Franchisees extends \lithium\data\Model {
protected $_schema = array(
'id' => 'id',
'name' => 'string',
'email' => 'string',
'password' => 'string',
'location' => 'string',
'days' => 'integer',
'status' => 'boolean'
);
public $validates = array(
'name' => array(
array('notEmpty', 'message'=>'You must include a name.')
),
'email' => array(
array('notEmpty', 'message'=>'You must include a email.'),
array('email', 'message'=>'email is not valid.'),
array('isUniqueEmail', 'message'=>'email is already used.')
),
'password' => array(
array('notEmpty', 'message'=>'You must include a password.')
),
'location' => array(
array('notEmpty', 'message'=>'You must include a location.')
)
);
}
输出:
array (size=7)
'id' => string '20' (length=2)
'name' => string 'test' (length=4)
'email' => string 'test4@gmail.com' (length=15)
'password' => string '123' (length=3)
'location' => string 'location1' (length=9)
'days' => string '4' (length=1)
'status' => string '1' (length=1)
上面的输出是所有字符串值,其中status,days,id不应该是字符串。