在 CakePHP 表单/模型的自定义验证中使用核心验证?
我了解 http 中的示例://book.cakephp.org/complete/1143/Data-Validation#Adding-your-own-Validation-Methods-1181 关于如何添加我自己的验证方法,但也许我遗漏了一些东西.
I understand the example at http://book.cakephp.org/complete/1143/Data-Validation#Adding-your-own-Validation-Methods-1181 on how to add my own validation methods, but maybe I'm missing something.
我只想验证 Field_B 是数字"(核心验证)如果 Field_A(选择/选项)等于某个值.
I only want to validate that Field_B is 'numeric' (a core validation) if Field_A (a select/option) is equal to a certain value.
好像我应该添加一个自定义验证,然后我用$this->data
检查其他字段的值,但是我如何调用一个自定义验证函数中的内置验证? 还是我做错了?
It seems that I'm supposed to add a custom validation, and then I check the values of other fields with $this->data
, but how do I call on a built-in validation from within a custom validation function? Or am I doing it wrong?
推荐答案
Validation::numeric($this->data['field'])
验证类 (validation.php) 位于 cake/cake/libs
中,您可以通过检查文件来查看可用的方法(它们与您传递给验证的方法相同)数组).
Validation class (validation.php) is located in cake/cake/libs
and you can see the available methods by inspecting the file (they're the same as the ones you pass to the validation array).
如果验证通过,验证方法返回 true.
Validation methods return true if validation passes.
相关文章