2011-10-28 65 views
1

我正在嘗試使用Security組件處理ControllerCakePHP 2.0,但我在做錯了它。在CakePHP中包含一個組件2

我讀過的documentation,但是當我包括我的Controller組件Security和我所說的控制器動作register我得到了blank page。如果我評論包括public $components = array('Security');它再次運作,我錯了?

<?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('[email protected]' => '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(); 
    } 
?> 

回答

0

如何在您的視圖文件中呈現註冊表單?

如果您使用安全組件,則需要使用FormHelper生成所有表單域。另外,當FormHelper給出一個值時,你就不能在前端隱藏值。