蛋糕php表单验证对我不起作用

0 validation cakephp

我有一个在cakephp中添加用户的first_name和last_name的表单.这是代码

视图代码(add.ctp)

<?php 
echo $this->Form->create('User');
echo $this->Form->input('first_name',array('label'=>'First Name'));
echo $this->Form->input('last_name',array('label'=>'Last Name'));           
echo $this->Form->end('Add User');
?>
Run Code Online (Sandbox Code Playgroud)

UserController(UsersController.php)的代码

<?php
     public function add(){
          if($this->request->is('post')){
               $addData = $this->request->data;
               $this->User->create();       
               if($this->User->save($addData)){
                  $this->Session->setFlash('User has been added successfully');
                  $this->redirect(array('action'=>'index'));            
               }            
          }
     }    
?>
Run Code Online (Sandbox Code Playgroud)

用户模型的查看代码(UserModel.php)

<?php
  class UserModel extends AppModel{
   public $validate = array(
     'first_name' => array(
          'rule'    => 'notEmpty',
          'message' => 'first name should not be empty.'
      ),
     'last_name' => array(
         'rule'    => 'notEmpty',
         'message' => 'last name should not be empty.'
      )
   );   
}
?>
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的代码,我已经在cakebook上看到并使用了其他各种规则,但是没有验证适用于我的表单.请问有什么可以帮助我的原因是什么?提前致谢!

ADm*_*mad 5

您的模型文件名不正确.应该User.php不是UserModel.php