1

I want to define the which Layout the Zend_Layout should use from Bootstrap class. How to do this?

Like from the controller you can do something like

$this->_helper->_layout = "somelayout";

I want to change the layout from the bootstrap class.

mrN
  • 3,734
  • 15
  • 58
  • 82
  • Would you be able to explain why you want to do it in bootstrap? It doesnt seem the right place.. perhaps you're trying to solve the wrong problem. – Duncan_m May 13 '11 at 05:12
  • @Duncan_m, I am trying to create different layout for a single website, which can be changed dynamically. So I need this. I can do it from a controller but then i would hvae to specify it in every controller, rather its better if i initialize in bootstrapper – mrN May 14 '11 at 08:24

2 Answers2

2

You could do it as follows:

public function _initLayout() {
    $layout = $this->bootstrap('layout')->getResource('layout');
    $layout->setLayout('somelayout');
}
gaRex
  • 4,144
  • 25
  • 37
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • 2
    +1 Provided, of course, that you had either initiated the layout in `application.ini` or with some `_initLayout()` method. ;-) – David Weinraub May 12 '11 at 12:43
  • Yes I have initiated the layout at the application.ini also, but the code above is giving a blank page. and somelayout.phtml does exists in the layout's script folder, which is the default layout path set in application.ini – mrN May 12 '11 at 14:08
  • @Marcin, @Alexander, do you know how to fix the blank page i am receiving. – mrN May 13 '11 at 06:25
  • @Marcin, No. I just get a blank page. If I create a empty mehod with `_iniLayout()` name. It will give the view script only without the layout part. – mrN May 13 '11 at 06:35
  • @Marcin, I found out it was in production mode. It is sending errors. `Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'Circular resource dependency detected'` – mrN May 13 '11 at 08:40
0

You can look further into it on these pages :

http://framework.zend.com/manual/en/zend.layout.quickstart.html

http://framework.zend.com/manual/en/zend.layout.options.html

The second one is more helpful, but make sure that you read "Using Zend_Layout with the Zend Framework MVC" in the first page.

If you want to start the layout strictly from the bootstrap you can do the following.


public function _initMyLayout()
{
     $options = array(
    'layout'     => 'somelayout',
    'layoutPath' => '/path/to/layouts',
    'contentKey' => 'CONTENT'
     };


     $layout = Zend_Layout::startMvc($options);

     return $layout;

}

The above would be equivalent to you specifying a default script and path in your .ini file.

Jerry Saravia
  • 3,737
  • 3
  • 24
  • 39