Believer
Believer

Reputation: 95

zend framework layouts

According to Rob Allen's tutorial : to use a layout into my zend application I should put:

$response = $this->getResponse();
$response->insert('header', $this->view->render('header.phtml')); 
$response->insert('sidebar', $this->view->render('sidebar.phtml')); 
$response->insert('footer', $this->view->render('footer.phtml')); 

into the init() function of the IndexController, to generate the header,footer and the sidebar for every action. I would like to use the same layout for all my views, should I put this portion of code into all the controllers??? (I'm using ZF 1.11)

thanks.

Upvotes: 0

Views: 1272

Answers (4)

RockyFord
RockyFord

Reputation: 8519

it's even easier then so far presented. In your application.ini add this line

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/" and the default layout at this path would be named layout.phtml.

If you want to change the path or the default layout you may need two lines in your application.ini

resources.layout.layoutPath = APPLICATION_PATH "/layouts"
resources.layout.layout = master

in this case the default layout would be master.phtml.

to change from the default layout to an alternate is as simple as adding:

public function preDispatch() {

        $this->_helper->layout->setLayout('admin');
    }

to the controller that needs a new layout, logic can be added so the alternate layout will only be applied to certain actions.

Upvotes: 0

Lee Davis
Lee Davis

Reputation: 4756

You can initialize a zend layout by doing the following in your bootstrap:

Zend_Layout::startMvc();

and you can also specify where your keeping your layouts

$layout = Zend_Layout::getMvcInstance();
$layout->setLayoutPath(__PATH_TO_LAYOUT_FOLDER_);

Once that's in place it will be much more efficient than rendering the same view in all your controllers.

Upvotes: 1

ChrisR
ChrisR

Reputation: 14467

The blogpost you are referring to is almost 5 years old and in no way represents the current state of ZF 1.11, you should use the official Zend_Layout documentation or Robs ZF1 tutorial

Upvotes: 1

Ismael Vacco
Ismael Vacco

Reputation: 1030

You want a layout default. You can make it calling in the template layout. The Zend Framework Documentation show it better: http://framework.zend.com/manual/en/zend.layout.quickstart.html

Upvotes: 0

Related Questions