1
我正在嘗試使用Security
組件處理Controller
的CakePHP 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();
}
?>