2011-06-02 56 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”视图脚本而不是常规视图脚本。