Zend Framework switching views in action
I have an action in a controller that is supposed to display different types 开发者_运维问答of output depending on the value in a dropdown on a form.
I have written a Templater object (extends from Zend_View_Abstract) for the different view types.
I have tried running the following code:
public function generateDocumentAction()
{
//...some code to set $view depending on post data
// e.g. $view = new TemplaterOdt(); //view as an OpenOffice document
$this->_helpers->getHelper('viewRenderer')->setView($view);
$this->view->myvar = $form->getValue('some_value');
}
but $this->view
is still the default one (a Smarty templater) which which is set in /public/index.php
I've looked in the documentation to and it says you can set the view in the init() function in the controller http://framework.zend.com/manual/en/zend.view.scripts.html but this would set the view for the entire controller which I don't want.
How can I change the output type for just this action?
If you just want to change the template to be rendered, use:
$this->_helper->viewRenderer('viewscripthere');
精彩评论