cakePHP验证
我正在从事一个cakePHP项目,并已设置了数据验证。我遇到的问题是,我一直从cakePHP的核心/模型中得到一个错误 错误是: 注意(8):未定义的偏移量:0[CORE/cake/libs/model/model.php,第2435行]cakePHP验证,php,cakephp,Php,Cakephp,我正在从事一个cakePHP项目,并已设置了数据验证。我遇到的问题是,我一直从cakePHP的核心/模型中得到一个错误 错误是: 注意(8):未定义的偏移量:0[CORE/cake/libs/model/model.php,第2435行] if (is_array($validator['rule'])) { $rule = $validator['rule'][0]; 我的验证规则如下所示: va
if (is_array($validator['rule'])) {
$rule = $validator['rule'][0];
我的验证规则如下所示:
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.'
)
);
var$validate=array(
'name'=>数组(
'rule'=>array('maxLength'=>80),
“必需”=>true,
'消息'=>'请输入您的姓名'
),
'address1'=>数组(
'rule'=>array('maxLength'=>80),
“必需”=>true,
'消息'=>'您忘记了地址'
),
'address2'=>数组(
'rule'=>array('maxLength'=>80),
'消息'=>'您的地址不能那么长吗
),
“城市”=>数组(
'rule'=>array('maxLength'=>80),
“必需”=>true,
“消息”=>“你的城市不会那么长吧?”
),
'zip'=>数组(
'rule'=>array('postal',null,'us'),
“必需”=>true,
'消息'=>'您的邮政编码不是corect格式。'
),
'电话'=>阵列(
'rule'=>array('phone',null,'us'),
“必需”=>true,
'消息'=>'您的电话号码不是corect格式。'
),
'电子邮件'=>数组(
'规则'=>'电子邮件',
“必需”=>true,
'消息'=>'请输入有效的电子邮件地址。'
),
'座位'=>阵列(
'规则'=>'数值',
“必需”=>true,
'消息'=>'您忘了告诉我们您需要多少座位。如果您不参加,请输入零(0)'
),
'带'=>数组的座位(
'rule'=>array('maxLength'=>80),
'消息'=>'请将此字段保持在80个字符以下。'
),
“cc_name”=>数组(
'rule'=>array('maxLength'=>80),
“必需”=>true,
“消息”=>“你忘了什么吗?”
),
“cc_编号”=>数组(
'rule'=>数组('cc','all',false,null),
“必需”=>true,
'消息'=>'您的信用卡号格式不正确。'
),
“cc_过期”=>数组(
'rule'=>数组('date','my'),
“必需”=>true,
'消息'=>'正确答案将采用以下格式MM/YYYY'
),
“cc_cvv”=>数组(
'规则'=>'数值',
“必需”=>true,
'消息'=>'请仅限数字。'
)
);
非常感谢您的帮助。您的问题在于规则语法: 就像您的其他规则一样,它是
,
,而不是=>
:数组('maxLength',80)
顺便说一句,我的城市有那么长:;-) 正是我需要的。多亏了德克塞,这是一个多么愚蠢的错误。我还将增加城市名称的大小。=)当你这样做的时候,你可以在“zip”和“phone”的消息中将“corect”的拼写改为“correct”。)
array('maxLength' => 80)