我有一个表格,它在 cakephp 中添加了用户的名字和姓氏。这是代码
视图代码 ( 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');
?>
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'));
}
}
}
?>
查看用户模型的代码 ( 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.'
)
);
}
?>
这是我正在使用的代码,我也在 cakebook 上看到并使用了各种其他规则,但没有验证适用于我的表单。有人可以帮我看看可能是什么原因吗?提前致谢!