我想将我的默认布局文件命名为 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/