Custom view Zend Framework



In zend framework MVC architecture it uses views according to the controller action. But I need to use a custom view for the result of the action like want to get cities options on change of country using ajax. Custom view zend framework without layout.

So I came to know this can be done by using $this->renderScript(‘ajax/file_path’) in zend framework.

Before this we need to disable the layout of the action by adding following line in action.

$this->_helper->layout->disableLayout();

Now in getcities action of our controller as follow:

        public function getcitiesAction(){
	      if ($this->getRequest()->isPost()){
	           $countryId = $this->getRequest()->getPost('country');
		   ..........
		   $this->view->cities = $countryModel->getCities($countryId);
	           $this->renderScript('ajax/cities_options.phtml');
              }
	}

To get selected country Id by

$this->getRequest()->getPost('country')

Now just call the function to get all related cities of the country and set for the view ‘cities_options.phtml’.

Finally rendered the custom view of action by

$this->renderScript('ajax/cities_options.phtml');

Hope this will help you.