我有一个视图,其中有2个表格。一个用于登录另一个用于注册。对于注册操作,我使用了操作
Users/add
我已在我的login.ctp
中提供了表单操作
<?= $this->Form->create($user, ['url' => ['action' => 'add']]); ?>
在添加动作中我编写了代码
public function add()
{
$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(__('The user has been saved.'));
return $this->redirect(['action' => 'login']);
}else{
$this->Flash->error(__('The user could not be saved. Please, try again.'));
return $this->redirect(['action' => 'login']);
}
}
$this->set(compact('user'));
}
现在,如果我发出任何验证错误,示例密码匹配验证错误,则此错误不会显示在字段password
下。但我能够看到它形成add.ctp。
如何发送此验证错误消息,从添加操作到登录操作?