1

I'm trying to working with Security component in a Controller of CakePHP 2.0 but I'm doing something wrong with it.

I've read in the documentation, but when I include the Security component in my Controller and I call the controller action register I get a blank page. If I comment the include public $components = array('Security'); it works again, where I'm wrong?

<?php
App::uses('CakeEmail', 'Network/Email');
class UsersController extends AppController {
    public $components = array('Security');

    public function register () {
        if (!empty($this->data)) {
            if ($this->data['User']['password'] == $this->data['User']['confirm_password']) {
                $this->User->create();
                $this->User->save($this->data);
                $this->registrationEmail ($this->data['User']['email'], $this->data['User']['username']);
                $this->redirect(array('controller'=>'users', 'action'=>'registration', 'success'));
            }
        }
    }
    private function registrationEmail ($account_email, $username) {
        $email = new CakeEmail('myconfig');
        $email->from(array('mailer@email.com' => 'MySite.com'));
        $email->to($account_email);
        $email->subject('Account activation / MySite.com');
        $email->template('activation');
        // $this->set('activation_code', Security->hash($account_email));
        $email->viewVars(
            array(
                'activation_code' => $this->Security->hash($account_email),
                'username' => $username
            )
        );
        $email->send();
    }
?>
4

1 回答 1

0

注册表单在您的视图文件中是如何呈现的?

如果您使用的是安全组件,则需要使用 FormHelper 生成所有表单字段。此外,一旦它们被 FormHelper 赋予了一个值,你就不能在前端摆弄隐藏的值。

于 2011-12-02T11:59:51.157 回答