2
cakePhp 앱을 사용하여 게임을 시작했지만 오류가있는 필드에 양식 도우미 출력 유효성 검사 오류 메시지를 표시 할 수 없습니다. FriendsOfCake/bootstrap-ui 플러그인을 사용하여 양식 도우미 출력 부트 스트랩 양식을 만드십시오.CakePhp 3.5 유효성 검사 오류 메시지가 필드에 나타나지 않습니다.
public function validationDefault(Validator $validator)
{
$validator
->integer('id')
->allowEmpty('id', 'create');
$validator
->notEmpty('name', 'Name should not be empty')
->scalar('name')
->requirePresence('name', 'create');
return $validator;
내 컨트롤러 방법 :
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user = $this->Users->patchEntity($user, $this->request->getData());
if ($this->Users->save($user)) {
$this->Flash->success(__('V-ati inregistrat cu success'));
return $this->redirect($this->referer());
}
$this->Flash->error(__('The user could not be saved. Please, try again.'));
}
$this->viewBuilder()->setLayout('auth');
$this->viewBuilder()->setTemplate('register');
$this->set(compact('user'));
$this->set('_serialize', ['user']);
}
및 내 양식 : 양식 도우미에 잘못된 컨텍스트를 전달하는
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<?=
$this->Form->create('users',['url'=>['controller'=>'Users','action'=>'store']]),
$this->Form->control('name'),
$this->Form->control('email'),
$this->Form->control('password'),
$this->Form->submit('Trimite'),
$this->Form->end()
?>
</div>
</div>
참조 정말 감사합니다. –