Using core validation within custom validation on CakePHP Forms/Models?(在 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.
这篇关于在 CakePHP 表单/模型的自定义验证中使用核心验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 CakePHP 表单/模型的自定义验证中使用核心验证
基础教程推荐
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01