cakephp에 user의 first_name과 last_name을 추가하는 양식이 있습니다. 여기 UserController에 대한 (add.ctp
)케이크 PHP 폼 유효성 검사가 작동하지 않습니다
<?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');
?>
코드 (UsersController.php
) 사용자 모델 (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.'
)
);
}
?>
에 대한
<?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'));
}
}
}
?>
보기 코드 코드를보기위한
코드입니다 이것은 내가 사용하고있는 코드이다. , 나는 케이크 책을 보았고 여러 가지 다른 규칙을 사용했지만 어떤 형태의 검증도 유효하지 않습니다. 이유가 될 수있는 일을 좀 도와 주실 수 있습니까? 미리 감사드립니다.