CakePhp 3.5验证错误消息不显示在字段上

问题描述:

所以我开始玩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> 

你传入一个无效的情况下,以形式帮手。 $context参数FormHelper::create()默认仅支持false/null,数组,结果集或实体,并且您希望传递后者,即$user变量,该变量包含包含可能的验证错误的实体。

$this->Form->create($user, [/* ... */]) 

+0

见太感谢你了,它的工作就像一个魅力。 –