Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json YII-在表单验证中添加错误代码_Json_Web Services_Validation_Error Handling_Yii - Fatal编程技术网

Json YII-在表单验证中添加错误代码

Json YII-在表单验证中添加错误代码,json,web-services,validation,error-handling,yii,Json,Web Services,Validation,Error Handling,Yii,我有一个web服务,希望在表单验证失败时发送自定义错误代码和字符串。我们可以在表单验证规则中指定错误“message”,但我想添加一个数字错误代码,以后可以使用它来获取文本字符串。扩展CValidator不是一个选项,因为我想使用标准验证器 理想情况下,我希望在规则函数中使用类似的内容 array('page', 'numerical', 'integerOnly' => true, 'min' => 1, 'message' => '{attribute} is i

我有一个web服务,希望在表单验证失败时发送自定义错误代码和字符串。我们可以在表单验证规则中指定错误“message”,但我想添加一个数字错误代码,以后可以使用它来获取文本字符串。扩展CValidator不是一个选项,因为我想使用标准验证器

理想情况下,我希望在规则函数中使用类似的内容

    array('page',  'numerical', 'integerOnly' => true, 'min' => 1, 'message' => '{attribute} is invalid', 'code' => 10079),
稍后我返回一个JSON块,如

    {
            'code': 10079,
            'message' : 'page is invalid'
    }

我正在考虑将一个行为附加到验证器上,但还不能找到一种使其工作的方法。还有其他方法吗?

您只需将错误代码作为消息返回,并在查看页面上调用函数来检索相应的错误消息,而不是消息

提供$form->error;作为参数在查看页面上获取errorMessage