Zend_Navigation 将类添加到活动链接
如何将类添加到活动导航链接?如果链接指向 URI /index/index 并且请求 URI 也是 /index/index,我希望该链接具有类,例如:
<li class="active">
<a href="/index/index">Index</a>
</li>
这就是我在引导程序中初始化导航的方式:
protected function _initNavigation()
{
$navigation = new Zend_Navigation($this->getOption('navigation'));
$this->view->navigation($navigation);
}
How can I add a class to the active navigation link? If a link points to URI /index/index and the request URI is also /index/index, I would like the link to have class, for example:
<li class="active">
<a href="/index/index">Index</a>
</li>
This is how I am initializing navigation in the bootstrap:
protected function _initNavigation()
{
$navigation = new Zend_Navigation($this->getOption('navigation'));
$this->view->navigation($navigation);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,
我已经通过编写控制器插件解决了这个问题:
Ok,
I have solved this by writing a controller plugin:
这是如何使用 Application 在 zend 框架的布局()中创建导航()。
好吧,至少有一种方法可以做到这一点。 CSS 类设置为
将其放入 Bootstrap.php 文件中:
这允许您为文件 menu.phtml 中的菜单创建一个数组,以便您仍然可以在当前链接上维护活动类。由于某些奇怪的原因,如果您使用它,则必须在数组中包含控制器属性才能获取当前链接上的 CSS 活动类。
将类似的内容放入 /layouts/scripts/menu.phtml 文件中:
将其放入layout.phtml 文件中:
This is how to create a navigation() in a layout() with zend frameworks using Application.
Well, at least one way of doing it. the CSS class is set on the
put this into the Bootstrap.php file:
This allows you to create an array for a menu in the file menu.phtml, so that you can still maintain the active class on the current link. For some strange reason, if you use this you must include the controller property in the array to get the CSS active class on the current link.
put something like this into the /layouts/scripts/menu.phtml file:
put this into the layout.phtml file: