我正在尝试创建一个帐户注册页面与CakePHP 2.0的用户需要激活它的新帐户点击后,他收到的电子邮件中的链接插入username,email和password的新帐户。
我的问题是如何在用户记录中设置激活码。
我想创建一个名为activation_code的表字段,然后存储username的hashed版本,以确保用户可以通过单击带有激活密钥的电子邮件链接来激活自己。
所有的过程都已经完成了,但是我不知道如何在$data['User']对象中设置activation_code,我也不清楚这是不是一个很好的使用MVC框架的方法,或者我应该用一种不同的方式来使用它。
在用户注册操作期间,我已经这样做了,但是当我尝试动态创建'activation_code‘时,我得到了一个错误:
// from the UserController class
public function register () {
if (!empty($this->data)) {
if ($this->data['User']['password'] == $this->data['User']['confirm_password']) {
// here is where I get the error
$this->data['User']['activation_key'] = AuthComponent::password($this->data['User']['email']);
$this->User->create();
if ($this->User->save($this->data)) {
// private method
$this->registrationEmail ($this->data['User']['email'], $this->data['User']['username']);
$this->redirect(array('controller'=>'users', 'action'=>'registration', 'success'));
}
}
}
}显然,activation_key在我的数据库中是一个空字段。
那么,如何从控制器动态创建一个文件呢?
发布于 2011-11-05 19:15:03
我已经用Model::set()方法解决了这个问题,所以:
public function register () {
if (!empty($this->data)) {
if ($this->data['User']['password'] == $this->data['User']['confirm_password']) {
$this->User->create();
// I've used set method
$this->User->set('activation_key', AuthComponent::password($this->data['User']['email']));
if ($this->User->save($this->data)) {
$this->registrationEmail ($this->data['User']['email'], $this->data['User']['username']);
$this->redirect(array('controller'=>'users', 'action'=>'registration', 'success'));
}
}
}
}发布于 2011-10-31 19:43:29
$this->data['User']['activation_key']应该是:
$this->request->data['User']['activation_key'](您应该将对$this->数据的所有引用更改为新的cakephp2.0 $this->request->data)
https://stackoverflow.com/questions/7946421
复制相似问题