【问题标题】:Cakephp rendering view in Shell is not workingShell中的Cakephp渲染视图不起作用
【发布时间】:2013-09-05 10:38:40
【问题描述】:

创建了一个 shell 类,EmailShell,它将呈现给定电子邮件模板的 html 并将其传递给 Mandrill Api 服务。

App::uses('View', 'Core');
class EmailShell extends AppShell {
    function startup() {
        parent::startup();
        $useDbConfig = 'default';
    }

    function new_user_created(){
        $html = $this->getEmailTemplateHtml('new_user');
        $post_fields['message'] = array(
            "html" => $html,
            "text" => strip_tags($html),
            "from_email" => "from@example.com",
            "subject" => "subject goes here.",
            "to" => "to@example.com"
        );
        $Mandril = ClassRegistry::init("Mandril");
        $Mandril->sendEmail($post_fields);
    }

    private function getEmailTemplateHtml($template, $layout = 'default', $custom_data = false){
        $v = new View();
        $v->set("data", $custom_data);
        return $v->render('Emails/'.$template, $layout);    
        }
    }

现在正在执行 shell 命令

$> 蛋糕电子邮件 new_user_created

它返回我以下错误消息。

*PHP 致命错误:在第 22 行的 C:\wamp\www\cakephp_application\app\Console\Command\EmailShell.php 中找不到类“视图”*

如何获取我的电子邮件模板的 html,以便将其传递给 Mandril 服务?

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    问题是ViewView文件夹中,没有Core文件夹。

    你会想用的。
    App::uses('View', 'View');

    【讨论】:

      猜你喜欢
      • 2015-11-11
      • 1970-01-01
      • 2014-01-19
      • 1970-01-01
      • 1970-01-01
      • 2017-02-27
      • 2011-07-28
      • 2016-02-09
      • 1970-01-01
      相关资源
      最近更新 更多