通过表单模型做接口,验证返回的错误明确错误信息如下:
/**
- 提取rules规则验证错误的信息
-
- @param [type] $model
-
@return void
*/
public static function getModelError($model) {
if(empty($model)) return true;
$errors = $model->getErrors(); //得到所有的错误信息
if(!is_array($errors)){
return true;
}
$firstError = array_shift($errors);
if(!is_array($firstError)) {
return true;
}
return array_shift($firstError);
}
调试的过程中通过打断点到$this->save() load() validate(),然后查看获取的
$this->errors、 $model->getErrors()会获取到详细的错误信息以方便一下步的调试