当尝试使用$ this-> data访问它时,为什么CakePHP密码字段为空? [英] Why is the CakePHP password field is empty when trying to access it using $this->data?
问题描述
我正在实施身份验证组件
这是我的注册页面
create('User',array('action'=>'login'));
echo $ form-> input('primary_email',array('size'=> 32));
echo $ form-> input('password',array('label'=>'Password'));
echo $ form-> input('remember_me',array('label'=>'Remember Me','type'=>'checkbox','checked'=>'false'))
echo $ html-> link('Forgot Password','/ users / forgot /');
echo $ form-> end('Login');
// Javascripts
echo $ javascript-> link('jquery',false);
// echo $ javascript-> link('jquery.validate.js',false);
// echo $ javascript-> codeBlock($ code,array('inline'=> false));
?>
当我打印$ this->数据密码字段变为空。
我如何解决这个问题?
当我将密码重命名为password2或其他的东西它工作!奇怪
我有同样的问题,mrlanrat的建议对我有用。
您无需访问$ this-> data ['password'],您需要访问$ this-> Auth-> data ['password']
<基本上发生的是,Auth组件散列密码并将散列版本移动到$ this-> Auth-> data。
因此,每当您需要处理与Auth组件相关的数据时,请确保您使用的是$ this-> Auth - >数据,而不是$ this-> data。
I am implementing an authentication component, This is my registration page
create('User',array('action' => 'login'));
echo $form->input('primary_email',array('size'=> 32));
echo $form->input('password',array('label' => 'Password'));
echo $form->input('remember_me',array('label' => 'Remember Me','type'=>'checkbox','checked' => 'false'));
echo $html->link('Forgot Password','/users/forgot/');
echo $form->end('Login');
// Javascripts
echo $javascript->link('jquery',false);
//echo $javascript->link('jquery.validate.js',false);
//echo $javascript->codeBlock($code, array('inline' => false));
?>
When I print the contents of $this->data the password field turns up empty. How can I resolve this?
When I rename password to password2 or something else it works !!! Strange
I had the same issue and mrlanrat's suggestion worked for me.
Instead of trying to access $this->data['password'], you will need to access $this->Auth->data['password']
What basically happens is that the Auth component hashes the password and moves the hashed version into $this->Auth->data. The non-hashed version is deleted for security purposes.
So whenever you need to deal with data related to Auth component, make sure you're using $this->Auth->data and not $this->data.
这篇关于当尝试使用$ this-> data访问它时,为什么CakePHP密码字段为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!