setting layout file for module inside bootstrap in

2019-06-07 21:05发布

问题:

My zend application structure:

application
  ->configs
  ->layouts
     ->scripts
        ->admin.phtml
        ->site.phtml
  ->modules
     ->admin(controllers, models, views)
       ->Bootstrap.php
     ->default(controller,models,views) 
       ->Bootstrap.php

I have set the default layout in my application.ini as:

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = "site"

I have two modules: admin and default. How to set the layout file (admin.phtml)for admin module? I want to change the layout from admin module's Bootstrap.php file? Or suggest me which is most easy way?

回答1:

Write this in your Bootstrap.php in the admin folder:

protected function _initLayout()
{
   $layout = Zend_Layout::getMvcInstance();
   $layout->setLayout('admin');
}

With the above two lines you can also change the layout in Controllers and Plugins. If you want to change it in a view, you can do that so:

<?php $this->layout()->setLayout('admin'); // set alternate layout ?>