2011-06-02 55 views
1

我是Zend的新手,我正在開發一個需要三個上下文來執行特定操作的項目。通常會使用標準上下文,用於AJAX調用的AJAX上下文,以及最後的打印友好上下文。我們的目標是爲每個那些有自己的看法,所以使用的視圖文件將是這樣的:Zend中的多個操作上下文

/action_name.phtml /action_name.ajax.phtml /action_name.print.phtml

我閱讀http://framework.zend.com/manual/en/zend.controller.actionhelpers.html並想出了:

public function init() 
{ 
    // add any necessary context switching here 
    $contextSwitch = $this->_helper->getHelper('AjaxContext'); 
    $contextSwitch->addActionContext('history', 'html') 
     ->initContext(); 
    //need to add another context for the print view 
    $this->_helper->getHelper('contextSwitch')->addActionContext('history','print')->initContext(); 
} 

前兩行我深信作品,但我不知道如果我要對打印上下文正確的方式,因爲在示例中的第二個參數通常是一個文件類型,如JSON,XML,HTML等。我是否正確的方式或事情有什麼我應該做的嗎?

回答

2

這一切都在documentation。如果你想自定義的背景下,你必須先添加它們:

$this->_helper 
    ->getHelper('contextSwitch') 
    ->addContext('print', array(
      // context options go here 
     )) 
    ->addActionContext('history', 'print') 
    // more addActionContext()s goes here 
    ->initContext(); 
0

你可能會做的,而不是利用上下文來進行打印預覽什麼是隻是像/print/1的URL的參數。然後在控制器操作中,檢查該參數是否爲true,如果是,則呈現「print」視圖腳本而不是常規視圖腳本。