【发布时间】:2011-09-18 17:02:53
【问题描述】:
我正在尝试从 CakePHP shell 发送电子邮件,就像您从 Controller 发送电子邮件一样。
下面的大部分代码都改编自this dated article on the Bakery,它是 cmets。电子邮件正在发送,但是$controller->set('result', $results[$i]); 行会引发以下通知:
注意:未定义的属性: 查看::$webroot 在 /home/jmccreary/www/intranet.sazerac.com/cakephp/cake/libs/view/view.php 813行
PHP 通知:未定义 变量:导致 /home/jmccreary/www/intranet.sazerac.com/cakephp/app/views/elements/email/text/nea/task_reminder_it.ctp 在第 2 行
所以我没有将任何变量传递到我的电子邮件视图。
我怎样才能做到这一点,最好遵循 Cake 约定?
class NotificationShell extends Shell {
var $uses = array('Employee', 'Task');
function main() {
// run if no action is passed
}
function nea_task_reminder() {
// build Task to Employee relationship
$this->Task->bindModel(array('belongsTo' => array('Employee' => array('className' => 'Employee', 'foreignKey' => 'object_id'))));
$results = $this->Task->find('all', array('conditions' => array('application_id' => 1, 'completed_by_id' => 0), 'contain' => array('Employee' => array('Contact', 'Position'))));
$count = count($results);
if ($count) {
App::import('Core', 'Controller');
App::import('Component', 'Email');
$controller =& new Controller();
$email =& new EmailComponent();
$email->startup($controller);
// send email
$email->from = Configure::read('Email.from');
$email->to = 'jmccreary@whatever.com';
$email->replyTo = 'no-reply@whatever.com';
$email->template = 'nea/task_reminder_it';
$email->sendAs = 'text';
for ($i = 0; $i < $count; ++$i) {
$email->subject = 'NEA Notification: Task Reminder for ' . $results[$i]['Employee']['Contact']['full_name'];
$controller->set('result', $results[$i]);
$email->send();
}
}
}
}
【问题讨论】: