0
我是CakePHP的新手,并且已经创建了一个提交名字的正常表单。 我的表名是“寄存器,我创建了一个名为RegistersController(RegistersController.php)控制器和一个名为注册(Register.php)模型。每次我进入第一个名字提交后,它仍然会显示错误(名字是必须的),它应该只有当我提交它没有输入任何东西,接下来我添加验证至少有6个字符,验证也不起作用,我的意思是,cakephp没有验证该规则。告诉我我在哪里做错了什么?CakePHP模型验证无法正常工作
型号: -
class Register extends AppModel {
//put your code here
//public $useTable = "registers";
public $validate = array(
'first'=>array(
'minLength' => array(
'rule' => array('minlength','6'),
'field' => 'first',
'message' => 'Minimum 6 characters required'
),
'required' => array(
'rule'=>array('notEmpty'),
'required' => true,
'message' => array('First name is must')
)
)
);
}
控制器: -
class RegistersController extends AppController {
public $uses = array("Register");
//put your code here
public function index() {
if($this->request->is('post')){
//echo "Data";
if($this->Register->validates()){
//$this->Register->create();
//echo "Data validated";
print_r($this->Register->validationErrors);
}else{
//echo "Data not validated";
print_r($this->Register->validationErrors);
}
}
}
我的看法如下: -
<?php
echo $this->Form->create('Register');
echo $this->Form->input('first');
echo $this->Form->end("Submit");
?>
它的工作。谢谢 –