且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

cakephp:使用$ validate数组验证登录表单

更新时间:2023-12-03 15:29:46

这将有助于看到你的代码。但是,从它的声音,你想显示他们试图使用的用户名。记住,对于视图和变量没有什么魔术。因此,为了显示他们试图使用的电子邮件地址,您可以将它直接放回文本字段(或放在任何你想要的地方)。我将向您显示两个选项:

It would be helpful to see your code. However, from the sounds of it, you want to show the username they attempted to use. Keep in mind there is nothing magic about the view and the variables. So to show the email address they attempted to use you could just put it right back in the text field (or put it anywhere you want). I will show you both options:

// back in the text field - login function in users_controller.php
function login() {
   $this->set('username', $this->data['User']['username']);
}

// to echo it outside of the text box
function login() {
   $this->set('uname', $this->data['User']['username']);
}

然后在视图中,您将执行以下操作:

Then in the view, you would do something like:

<?php
  if (!empty($uname)) {
     echo $uname;
  }
?>

快乐编码!