Hello everyone,

I have a question about automatic append of a view when calling $this->render('script'). In several controllers actions, I want to return JSON with 2 html code into it. For theses actions, I have e.g. 2 views scripts in the corresponding view directory, namely list.phtml and content.phtml.
I want to have the following code to perform this :

// Iterable object used for the list
$this->view->iterablesThings = $things;
$json = array(
   'list' => $this->render('list'),
   'content' => $this->render('content')
);
echo Zend_Json::encode($json);
return;

This make the code for handling ajax and normal request quite similar and I like it :) Anyway, as I dug into the code, I didn't found any method to get the result of the render instead of it being appended to the body.
Right now I added the following code in my App_Controller_Action :

public function renderView($action = null, $name = null, $noController = false)
{
   $view   = $this->initView();
   $script = $this->getViewScript($action, $noController);
   return $view->render($script);
}

Calling $this->renderView instead of $this->render does the job, but any of you know a better way to do this? Should I initialize things when getting ajax call ? Right now I have in the init() :

if($this->getRequest()->isXmlHttpRequest() || $this->getRequest()->isFlashRequest()) {
   $this->_layout = false;
   $this->getHelper('viewRenderer')->setNoRender();
   // Other things ?
}

Thanks,
Baptiste.

Reply via email to