在CakePHP表单/模型的自定义验证中使用核心验证? [英] Using core validation within custom validation on CakePHP Forms/Models?

查看:101
本文介绍了在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表单/模型的自定义验证中使用核心验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆