我在試圖弄清楚爲什麼我無法在我的電子郵件CakePHP 2.0的模板中使用$ this-> Html-> url。 Helpers數組在視圖中是空的。這是由設計還是我錯過了什麼?CakePHP 2:電子郵件模板中的Html Helper
文檔和移植指南沒有提到任何事情。
跟蹤的樣子:
include - APP/View/Emails/html/admin/users_recover.ctp, line 1
View::_render() - CORE/Cake/View/View.php, line 598
View::render() - CORE/Cake/View/View.php, line 365
CakeEmail::_render() - CORE/Cake/Network/Email/CakeEmail.php, line 1300
CakeEmail::send() - CORE/Cake/Network/Email/CakeEmail.php, line 933
UsersController::_sendRecoverEmail() - APP/Controller/UsersController.php, line 186
UsersController::admin_login() - APP/Controller/UsersController.php, line 101
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE/Cake/Controller/Controller.php, line 476
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 106
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 88
[main] - APP/webroot/index.php, line 96
這裏是我發送恢復電子郵件的功能:
private function _sendRecoverEmail($email, $recoverKey) {
App::uses('CakeEmail', 'Network/Email');
$cakeEmail = new CakeEmail();
$cakeEmail->config('default');
$cakeEmail->to($email);
$cakeEmail->subject('Recover Your '. Configure::read('Site.title') . ' Account');
$cakeEmail->template('admin/users_recover');
$cakeEmail->viewVars(array(
'recoverKey' => $recoverKey,
));
try {
$cakeEmail->send();
} catch (Exception $e) {
trigger_error("ERROR in UsersController::sendRecoverEmail: couldn't send email to: {$email}.");
return false;
}
return true;
}
最後,認爲:
<p>Have you been having difficulty getting into your <?php echo Configure::read('Site.title'); ?> account?</p>
<?php $url = $this->Html->url(array('action' => 'recover', 'controller' => 'users', $recoveryKey), true); ?>
<p>If this is correct, <a href="<?php echo $url; ?>">click here to recover your access and create a new password.</a></p>
<p>Your password will remain the same if you ignore it.</p>
你能粘貼一些示例代碼和相關文件路徑顯示在那裏你的問題在哪裏? – Ivo
更多的信息和代碼已添加。 –