簡體   English   中英

Zend:在命令行中生成局部

[英]Zend: Generating partial in command line

我有一組課程,可以將郵件發送給我的同事,同時發生特定事件。 到目前為止,到目前為止,我對此沒有任何問題。 我必須從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

那么...如何在終端中渲染局部圖像?

根據此: 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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM