[英]cakePHP validation
I am working on a cakePHP project and have set up my data validation. 我正在开发cakePHP项目并设置了我的数据验证。 The problem i have is that i keep getting an error from the core/model of cakePHP. 我遇到的问题是我不断从cakePHP的核心/模型中得到错误。
The error is: Notice (8): Undefined offset: 0 [CORE/cake/libs/model/model.php, line 2435] 错误是:注意(8):未定义的偏移量:0 [CORE / cake / libs / model / model.php,第2435行]
if (is_array($validator['rule'])) {
$rule = $validator['rule'][0];
My validation rules look like this: 我的验证规则如下所示:
var $validate = array( 'name' => array( 'rule' => array('maxLength' => 80), 'required' => true, 'message' => 'Please enter your name' ), 'address1' => array( 'rule' => array('maxLength' => 80), 'required' => true, 'message' => 'You forgot your address' ), 'address2' => array( 'rule' => array('maxLength' => 80), 'message' => 'Your address can\'t be that long?' ), 'city' => array( 'rule' => array('maxLength' => 80), 'required' => true, 'message' => 'Your city can\'t be that long?' ), 'zip' => array( 'rule' => array('postal', null, 'us'), 'required' => true, 'message' => 'Your zip code is not in the corect format.' ), 'phone' => array( 'rule' => array('phone', null, 'us'), 'required' => true, 'message' => 'Your phone number is not in the corect format.' ), 'email' => array( 'rule' => 'email', 'required' => true, 'message' => 'Please enter a valid email address.' ), 'seats' => array( 'rule' => 'numeric', 'required' => true, 'message' => 'You forgot to let us know how many seats you need. If you will not be attending please enter a zero (0)' ), 'seat_with' => array( 'rule' => array('maxLength' => 80), 'message' => 'Please keep this field below 80 charcters.' ), 'cc_name' => array( 'rule' => array('maxLength' => 80), 'required' => true, 'message' => 'Did you forget something?' ), 'cc_number' => array( 'rule' => array('cc', 'all', false, null), 'required' => true, 'message' => 'Your credit card number is not in the correct format.' ), 'cc_expiration' => array( 'rule' => array('date', 'my'), 'required' => true, 'message' => 'The correct answer will be in the following format MM/YYYY' ), 'cc_cvv' => array( 'rule' => 'numeric', 'required' => true, 'message' => 'Numbers only please.' ) );
Any help is much appreciated. 任何帮助深表感谢。
Your problem is in the rule syntax: 您的问题在于规则语法:
array('maxLength' => 80)
Just like your other rules, it's ,
, not =>
: array('maxLength', 80)
. 就像你的其他规则,这,
不是=>
array('maxLength', 80)
BTW, my city can be that long: http://en.wikipedia.org/wiki/Krung Thep Mahanakhon Amon Rattanakosin Mahinthara... ;-) 顺便说一句,我的城市可以那么长: http : //en.wikipedia.org/wiki/Krung Thep Mahanakhon Amon Rattanakosin Mahinthara ...... ;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.