Shell中的Cakephp渲染视图不起作用


Cakephp rendering view in Shell is not working

创建了一个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致命错误:在C:''wamp''www''cakehp_application''app''Console''Command''EmailShell.PHP的第22行*中找不到类"View"

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

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

您将想要使用
App::uses('View', 'View');