0

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.

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

OK thanks you for the links, I didn't know there is a tutorial for the the new versions.
0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.