我有一组课程,可以发送邮件给我的同事,同时发生特定事件。到目前为止,我对此没有任何问题,直到今天。我必须运行CLI
(目标 - 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
那么...如何在终端中渲染部分?
答案 0 :(得分:2)
根据这个:http://framework.zend.com/manual/1.12/en/zend.layout.quickstart.html
// Returns null if startMvc() has not first been called
$layout = Zend_Layout::getMvcInstance();
所以,如果你没有添加这个:
// In your bootstrap:
Zend_Layout::startMvc();
您无法访问此内容 -
Zend_Layout::getMvcInstance()->getView()
所以尝试这样做:
Zend_Layout::startMvc();
Zend_Layout::getMvcInstance()->getView();