Zend Layout - 一个“智能”布局布局选择器
我目前有 Zend 设置来在每个模块的 view/scripts/layout.phtml 文件(即:/application/modules/moduleName/scripts/layout.phtml)中查找布局脚本。这是通过在 application.ini 文件 (resources.layout[] =
) 中将layout[] 设置为空(空白)来实现的。
问题是许多模块可能共享相同的布局。我不想将相同的布局复制到使用它的每个模块中。我知道我可以通过设置像 resources.layout.layoutpath = /layoutPath
这样的特定路径来将所有内容设置为使用一个布局脚本,并且所有内容都将使用 /layoutpath/layout.phtml,而且我知道我可以设置单独的页面(或整个控制器,在 init 中)使用 $this->_helper->layout->setLayout('foobaz');
问题是某些模块将具有不同的布局,除了“标准”之外,我不想根据控制器或操作来设置它。我想为整个模块设置它,设置在一个地方(或者通过代码/Zend自动直观地计算出来)。理想情况下,它将按照当前的方式设置,但如果模块没有自己的layout.phtml,它将使用默认模块的布局。
那么...我该怎么做呢?
I currently have Zend setup to look for a layout script in each module's view/scripts/layout.phtml file (ie: /application/modules/moduleName/scripts/layout.phtml). This is by setting layout[] to nothing (blank) in the application.ini file (resources.layout[] =
)
The issue is that many modules may share the same layout. I don't want to copy the same exact layout into each module that uses it. I know I can set everything to use one layout script by setting a specific path like resources.layout.layoutpath = /layoutPath
and everything would use /layoutpath/layout.phtml, and I know I can set individual pages (or whole Controllers, in the init) by using $this->_helper->layout->setLayout('foobaz');
The issue is that some modules will have different layouts, other than the 'standard' one, and I don't want to set it on a by Controller or by Action basis. I want to set it for the entire module, set in one place (or intuitively figured out by code/Zend automatically). Ideally, it would be setup how it is currently, but if a module doesn't have its own layout.phtml, it would use the default module's layout.
So... how do I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有几种解决方案,选择适合自己的策略
1 扩展动作控制器
然后照常做
IndexController extends App_Controller_Action ...
如果布局文件存在于 APPLICATION_PATH 中。 '/模块/' 。 $模块名称。 '/layouts' 目录 - 它将代替默认布局
2 使用,您可以编写 frontcontroller 插件
,并且不要忘记 google 寻找其他解决方案;)
There are several solutions, choose their own strategy
1 extending the action controller
and then do as usual
IndexController extends App_Controller_Action ...
if layout file exists in
APPLICATION_PATH . '/modules/' . $moduleName . '/layouts'
directory - it will ne used instead of default layout2 you can write frontcontroller plugin
and dont forget to google for another solutions ;)
您可以通过几个步骤设置自己的布局选择器
第 1 步:
使模块成为管理员和默认模块。
步骤2:
在每个模块中创建布局文件夹作为 admin/layouts/scripts
和默认/布局/脚本
放入layout.phtml
第3步:
从Application/layouts/scripts 中删除layout.phtml 文件。
第4步:
在库中创建 Plugin 文件夹并创建 Plugin.php
步骤
5:
打开Application/configs/Appication.ini文件
并编辑它
步骤
6:
打开引导文件Application/Bootstrap
把代码放进去
you can set own layout selector in few steps
step 1:
make module admin and default.
step 2:
create layout folder in each module as admin/layouts/scripts
and default/layouts/scripts
put into layout.phtml
step 3:
delete the layout.phtml file from Application/layouts/scripts.
step 4:
make the the Plugin folder inside library and make Plugin.php
as
step 5:
open Application/configs/Appication.ini file
and edit it
as
Step 6:
open bootstrap file Application/Bootstrap
put the code inside
最快的解决方案可能是创建一个符号链接,将模块布局文件指向默认布局。这在 Windows 上不起作用并且更难维护。
更好的是,在 Bootstrap 中创建一个方法来设置布局。
请参阅 http:// /framework.zend.com/manual/en/zend.application.quick-start.html#zend.application.quick-start.resources 了解更多详细信息。
最后,您可以 编写您自己的应用程序资源以与 Zend_Application 一起使用。
The quickest solution might be to create a symlink to point what would be a module layout file to the default layout. This won't work on Windows and is harder to maintain.
Better, create a method in your Bootstrap to set the layout.
See http://framework.zend.com/manual/en/zend.application.quick-start.html#zend.application.quick-start.resources for more details.
Finally, you could write your own application resource for use with Zend_Application.