2
所以我開始玩cakePhp應用程序,試圖使它工作,但我不能使窗體幫助器輸出驗證錯誤消息的字段與error.I是使用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>
見太感謝你了,它的工作就像一個魅力。 –