php - Zend 框架 : How do I change the default layout script to something other than layout. phtml?

标签 php zend-framework

我想将我的默认布局文件命名为 layout.phtml 以外的名称,因为它并没有真正描述它是什么类型的布局。我怎样才能做到这一点?谢谢!

最佳答案

在您的 Bootstrap.php 文件中,您可以执行如下操作:

protected function _initLayoutName()
{
    // use sitelayout.phtml as the main layout file
    Zend_Layout::getMvcInstance()->setLayout('sitelayout');
}

如果你想为不同的模块使用不同的布局,你需要在Bootstrap中注册一个插件,并让插件包含以下代码:

class Application_Plugin_LayoutSwitcher extends Zend_Controller_Plugin_Abstract
{
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {
        $module = $request->getModuleName(); // get the name of the current module

        if ('admin' == $module) {
            // set the layout to admin.phtml if we are in admin module
            Zend_Layout::getMvcInstance()->setLayout('admin');
        } else if ('somethingelse' == $module) {
            Zend_Layout::getMvcInstance()->setLayout('somethingelse');
        }
    }
}

在您的 application.ini 中,您可以这样做来设置布局脚本:

resources.layout.layout = "layoutname"

但是,这不适用于每个布局。如果您需要根据模块更改布局,则必须使用插件,但您可以使用 application.ini 中的设置来设置默认布局名称。

关于php - Zend 框架 : How do I change the default layout script to something other than layout. phtml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9136953/

相关文章:

php - 使用 cURL 请求 instagram api 访问 token

iis - 处理同一个域下的多个应用程序

zend-framework - Zend Gdata 总是需要 SSL?

php - 即(HTTPS): generating pdf from php file doesn't work

php - 我无法提交表格

php - Zend Framework 1.12 中的 SQL 子查询

Zend Framework 中的 MySQL 资源

php - 如何在我的旧 PHP 非集中站点上集成 Zend Framework?

javascript - PHP 后端与 JS xHTMLRequest 前端

PHP 时间流逝与 MySQL DateTime