如何在 Zend 布局中检索参数
我正在阅读《Zend Framework - 初学者指南》一书。 第三章的一部分描述了主布局的使用。
对于我的导航,我想动态设置正文的 id-attrib。如何从任何控制器获取参数到该布局文件?
主布局在 application.ini 中设置:
resources.layout.layoutPath = APPLICATION_PATH "/layouts"
resources.layout.layout = master
greetings 坦率
I'm working through the book "Zend Framework - A beginners guide".
Part of the third chapter describes working with a masterlayout.
For my navigation I'd like to set the id-attrib of the body dynamically. How can I get a parameter from any controller to this layout-file?
The master-layout is set in application.ini:
resources.layout.layoutPath = APPLICATION_PATH "/layouts"
resources.layout.layout = master
greetings
Frank
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将视图变量用于需要传递到布局脚本中的简单变量:
在您的控制器中:
在您的布局脚本中:
You can use view vars for simple variables you need to pass into layout scripts:
In your controller:
In your layout script:
做到这一点的最佳方法是使用占位符。下面是一个示例布局:
请注意,“id”属性的值以“
”开头。这与“
”相同,如果您使用 Zend 推荐的默认 .htaccess 文件,它应该可以正常工作。如果“
”对您不起作用,只需将其替换为:
现在,在您的控制器中,您可以使用以下方法设置动态 id:
The best way to do this, is to use placeholders. Here's an example layout:
Note that the value for the "id" attribute starts with "
<?=
". This is the same as "<?php echo
" and it should work correctly if you're using the default .htaccess file which Zend recommends. If "<?=
" does not work for you, simply replace it with:Now, in your controller, you can set your dynamic id using: