Php Zend:在命令行中生成部分
我有一套在特定事件发生时向同事发送邮件的类。到目前为止,我对此没有任何问题,直到今天。我必须从Php Zend:在命令行中生成部分,php,zend-framework,Php,Zend Framework,我有一套在特定事件发生时向同事发送邮件的类。到目前为止,我对此没有任何问题,直到今天。我必须从CLI(target-cron)运行一些代码来发送每日报告。正如您可能怀疑的那样-不涉及控制器或视图 我的代码: /** * Returns mail content * * @param Crm_Mail_Abstract_AlertMail $object * @return string * @throws Exception */ private function generate
CLI
(target-cron
)运行一些代码来发送每日报告。正如您可能怀疑的那样-不涉及控制器或视图
我的代码:
/**
* Returns mail content
*
* @param Crm_Mail_Abstract_AlertMail $object
* @return string
* @throws Exception
*/
private function generateContent(Crm_Mail_Abstract_AlertMail $object)
{
$subContent = $object->getInnerContent();
if (!$subContent) {
throw new Exception('Cannot load subcontent');
}
$view = Zend_Layout::getMvcInstance()->getView();
$content = $view->partial($this->mainLayout, array('content' => $subContent));
return $content;
}
我得到的错误是:
PHP Fatal error: Call to a member function getView() on a non-object
in /home/..../library/Crm/Mail/AlertMail.php on line 195
所以。。。如何在终端中呈现片段?根据以下内容:
因此,如果您没有添加以下内容:
// In your bootstrap:
Zend_Layout::startMvc();
您将无法访问此-
Zend_Layout::getMvcInstance()->getView()
所以试着这样做:
Zend_Layout::startMvc();
Zend_Layout::getMvcInstance()->getView();
Zend_Layout::startMvc();
Zend_Layout::getMvcInstance()->getView();