如何为每个模块设置单独的布局?

时间:2010-08-27 22:06:55

标签: php zend-framework

我有这样的配置文件

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[database]
resources.db.adapter               = PDO_MYSQL
resources.db.params.dbname         = "ccgss"
resources.db.params.username       = "root"
resources.db.params.password       = ""
resources.db.params.hostname       = "localhost"
resources.db.isDefaultTableAdapter = true

[layout]
layoutPath = APPLICATION_PATH "/modules/default/layouts"
contentKey = "content"

这适用于默认模块,但后来我有管理面板,布局完全不同。如何设置管理模块的布局?

2 个答案:

答案 0 :(得分:1)

在您的控制器中,您可以设置布局:

    $layout = Zend_Layout::getMvcInstance();
    $layout->setLayout('admin');
    $layout->setLayoutPath(APPLICATION_PATH . '/modules/admin/layouts');

也许在preDispatch中做到这一点

答案 1 :(得分:1)

application.ini

resources.layout.layout = "layout"
resources.layout.layoutPath = APPLICATION_PATH "/layouts"
admin.resources.layout.layout = "admin"
admin.resources.layout.layoutPath = APPLICATION_PATH "/modules/admin/layouts"

您还可以根据请求参数动态创建控制器插件切换布局。

有关详细信息,请参阅:http://blog.astrumfutura.com/archives/415-Self-Contained-Reusable-Zend-Framework-Modules-With-Standardised-Configurators.html