Zend Framework:是否有视图助手在布局类中显示视图名称?
正如标题所示,我试图找到一种显示当前作为布局一部分显示的视图标题的方法。我正在尝试执行此操作,以便在选择不同视图时动态填充页面标题。
在伪代码中:
<div>
<div id="header"><h1>My website</h1></div>
<div id="main">
<?php echo "<h2>" . SOME WAY OF ECHOING THE VIEW NAME HERE . "</h2>"; ?>
<?php echo $this->layout()->content; ?>
</div>
<div id="footer"><p>2011 My website.com></p>
</div>
我已经浏览了 Zend 文档,我能找到的最接近的东西是标题链接。但是,我无法从此帮助程序获取值并将其插入变量中,以便我可以将其文本显示为视图的页面标题。
谢谢。
As the title suggests, I'm trying to find a way of displaying the title of the View currently being displayed as part of the layout. I'm trying to do this so that the page title is dynamicly populated when a different view is selected.
In psuedocode:
<div>
<div id="header"><h1>My website</h1></div>
<div id="main">
<?php echo "<h2>" . SOME WAY OF ECHOING THE VIEW NAME HERE . "</h2>"; ?>
<?php echo $this->layout()->content; ?>
</div>
<div id="footer"><p>2011 My website.com></p>
</div>
I've been through the Zend documentation and the closest thing I could find was the headlink. However, I was unable to get the value from this helper and shoehorn it into a variable so that I could display its text as a page header for the view.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将操作名称(或根据需要与模块组合)传递到控制器内的布局。
$layout = $this->_helper->layout->getLayoutInstance();
$layout->viewName = $this->_getParam("action");
有点脏,但可以用
You could pass the action name (or combine with the module if needed) to the layout within the controller.
$layout = $this->_helper->layout->getLayoutInstance();
$layout->viewName = $this->_getParam("action");
Kind of dirty, but it would work
我不太确定我是否理解正确,但是有一个叫做 ZendFramework 中的占位符。基本上,您定义占位符,然后用您想要的任何内容填充它。
I´m not quite sure if I understood you right, but there´s something called a placeholder in ZendFramework. Basically you define the placeholder and fill it afterwards with whatever you want.