开发者

Zend Framework: How to attach other than default layout

开发者 https://www.devze.com 2023-03-16 13:33 出处:网络
I have createda module \'admin\' . I also created a layout for this admin module. How can I permanently attach this layout to \'admin\' module. Can some one suggest me where and how can I write code f

I have created a module 'admin' . I also created a layout for this admin module. How can I permanently attach this layout to 'admin' module. Can some one suggest me where and how can I write code for this purpose. Whether it w开发者_Go百科ould be in bootstrap file ?


If this is a module like you say you can simply add a layout.phtml file into the module's layout/scripts/ folder.

If you have a different name for your layout.phtml like admin.phtml you simple add the following in your controller

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

It should and will check first the module's layout folder and then the default folder.


you can specify alternative path for layout scripts:

if (!$registered) {
//for PUBLIC role
  Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH.'/layouts/scripts/pub');
} else {
//For registered users
  Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH.'/layouts/scripts');
}


In your bootstrap file

protected function _initAutoloader() {
        $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => '',
            'basePath'  => APPLICATION_PATH . '/modules/default'), array(
            'namespace' => 'Admin',
            'basePath'  => APPLICATION_PATH . '/modules/admin'
        )            
      );
      return $autoloader;

    }

application.ini

phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
includePaths.library = APPLICATION_PATH "/../library"
appnamespace = "Default"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.defaultModule = "default"
resources.frontController.defaultController = "index"
resources.frontController.defaultAction = "index"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = "layout"
resources.modules = ""
resources.view[] =

and in each controller of admin you need to add this line to the init function to change the layout.

$this->_helper->layout()->setLayout("admin");

0

精彩评论

暂无评论...
验证码 换一张
取 消