久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

CakePHP 使用來自 Shell cronjob 的電子郵件組件

CakePHP using Email component from Shell cronjob(CakePHP 使用來自 Shell cronjob 的電子郵件組件)
本文介紹了CakePHP 使用來自 Shell cronjob 的電子郵件組件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試像從控制器一樣從 CakePHP shell 發送電子郵件.

I'm trying to send an email from a CakePHP shell just as you would from the Controller.

以下大部分代碼改編自 這篇關于面包店的過時文章 及其評論.電子郵件正在發送,但是行 $controller->set('result', $results[$i]); 拋出以下通知:

Most of the code below was adapted from this dated article on the Bakery and it's comments. The email is sending, however the line $controller->set('result', $results[$i]); throws the following notices:

注意:未定義的屬性:查看::$webroot/home/jmccreary/www/intranet.sazerac.com/cakephp/cake/libs/view/view.php在線 813

Notice: Undefined property: View::$webroot in /home/jmccreary/www/intranet.sazerac.com/cakephp/cake/libs/view/view.php on line 813

PHP 注意:未定義變量:導致/home/jmccreary/www/intranet.sazerac.com/cakephp/app/views/elements/email/text/nea/task_reminder_it.ctp第 2 行

PHP Notice: Undefined variable: result in /home/jmccreary/www/intranet.sazerac.com/cakephp/app/views/elements/email/text/nea/task_reminder_it.ctp on line 2

所以我沒有將任何變量傳遞給我的電子郵件視圖.

So I'm not getting any of the variables passed to my email view.

我怎樣才能做到這一點,最好遵循 Cake 約定?

How can I do this, ideally following the Cake conventions?

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();
            }
        }
    }
}

推薦答案

問題在于您初始化 EmailComponent 類的方式.如果您查看源代碼,startup() 方法實際上沒有主體,因此它什么也不做.您的控制器實際上并未分配給 EmailComponent.問題不在于 $controller->set('results', ...);.您需要使用 EmailComponent::initialize() 而不是 EmailComponent::startup().

The problem is the way you're initializing the EmailComponent class. If you look at the source code, the startup() method doesn't actually have a body so it does nothing. Your controller isn't actually assigned to the EmailComponent. The problem isn't $controller->set('results', ...);. You need to use EmailComponent::initialize() instead of EmailComponent::startup().

$controller =& new Controller();
$email =& new EmailComponent(null);
$email->initialize($controller);

來源:

  1. http://的評論部分/bakery.cakephp.org/articles/Jippi/2007/12/02/emailcomponent-in-a-cake-shell
  2. EmailComponent::startup() 來源

這篇關于CakePHP 使用來自 Shell cronjob 的電子郵件組件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 国产黄色一级电影 | 麻豆视频在线看 | 久久久精品高清 | 国产 欧美 日韩 一区 | 高清国产午夜精品久久久久久 | 精品欧美色视频网站在线观看 | 中文字幕高清 | 亚州影院 | 亚洲香蕉在线视频 | 久久国产一区 | 在线看91 | 欧美日韩在线观看一区 | 欧美精品一区在线发布 | 欧美一区二区三区在线观看视频 | caoporn免费在线视频 | 一区二区三区四区不卡 | 久久久久久九九九九九九 | 午夜国产一级 | 欧美视频三区 | 精品综合久久久 | 欧美久久久久久久久 | 91精品麻豆日日躁夜夜躁 | 欧美国产亚洲一区二区 | 国产欧美精品一区二区 | 成人午夜精品一区二区三区 | 91视频在线 | 国产一二三区在线 | 亚洲毛片在线 | 国产视频线观看永久免费 | 欧美一级片在线播放 | 国产在线精品一区二区三区 | 777毛片| 亚洲一区二区三区在线播放 | 毛片一级网站 | 免费视频一区二区 | 精品日韩| 久久av资源网 | 亚洲一区二区三区免费视频 | 伊人青青久久 | 看av片网站 | 欧美一区免费 |