How to use multiple layouts with different action in Zend Framework

To read this post ,am guessing that you are quite familiar with zend framework’s basic layout concept ,if not then read my post http://www.waytocode.com/?p=430 first ,After that you can understand below advanced topics.

The Default layout name set in application.ini

resources.layout.layoutPath = APPLICATION_PATH “/layout/script”
resources.layout.layout = “layout

here layout mean you have one layout.phtml file in your layout folder.

So to use different layout ,you need to create another layout file in your layout folder as layout2.phtml (just near to layout.phtml)

If you want to set newly created layout2 as your layout from Controller page

1
2
3
4
public function registerAction()
{
     $this->_helper->layout->setLayout('layout2');
}

If you want to set newly created layout2 layout from view page

1
2
3
<?php
   layout()->setLayout('layout2');
?>

Now you can get the new design be pointing to the controller/action in browser.

http://localhost/film/public/signup/register

Am pointing to register action as i have set new layout in register action of my controller page called

signup .

How to Disable layout for a perticular action

1
2
3
4
public function registerAction()
{
   $this->_helper->layout->disableLayout();
}