如何装饰 zend 导航菜单?
我有这个菜单:
$menu['talent'] = array(
array('id' => 'welcome',
'label' => 'My Profile',
'uri' => '/profile/,
'class' => 'navlink'
)
),
array('id' => 'welcome',
'label' => 'My Profile',
'class' => 'navlink',
'uri' => '/profile/
),
);
最终看起来像这样:
<ul>
<li><a href="" class="navlink">My Profile</a></li>
<li><a href="" class="navlink">My Profile</a></li>
<ul>
我如何将 ul
更改为 div
并将 li
更改为其他内容?
有伊达吗?
谢谢
i have this menu:
$menu['talent'] = array(
array('id' => 'welcome',
'label' => 'My Profile',
'uri' => '/profile/,
'class' => 'navlink'
)
),
array('id' => 'welcome',
'label' => 'My Profile',
'class' => 'navlink',
'uri' => '/profile/
),
);
this will end up looking like this:
<ul>
<li><a href="" class="navlink">My Profile</a></li>
<li><a href="" class="navlink">My Profile</a></li>
<ul>
how can i change the ul
into a div
and also the li
into something else?
any idas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,为了实现这一点,我将使用以下两种方法之一:
使用 View Helper 和重载 menu()
为了重载
Zend_View_Helper_Navigation_Menu
,您可以编写自己的帮助程序,注册它并使其扩展<代码>Zend_View_Helper_Navigation_Menu。在助手中,您可以重载所需的方法,例如_renderMenu()
并使其渲染而不是
例如。在你的视图助手中,你必须返回parent::menu()或类似的东西。
最后,您必须使用以下方法注册这个新的视图助手:
使用部分脚本
在我看来,这个脚本有点长,但值得一试。
基本上,您需要使用
setPartial()
方法为导航设置部分脚本,并且您的菜单将通过此部分呈现。然后,在 _nav.phtml 中,您可以根据需要呈现菜单。在此部分中,您可以使用
$this->container
访问菜单变量。然后,您可以遍历容器的每个页面,并显示您想要的内容。我知道对于这样一个简单的任务来说,所有这些看起来都相当复杂,但不幸的是,这是唯一的解决方案。有人有更好的主意吗?
Well, to accomplish this I would use one of these two methods:
Using a View Helper and overload menu()
In order to overload
Zend_View_Helper_Navigation_Menu
, you could write you own helper, register it and make it extendsZend_View_Helper_Navigation_Menu
. In your helper, you can overload the method you want such as_renderMenu()
and make it renders<p>
instead of<li>
for example. In your View Helper, you would have to return the parent::menu() or something like this.Finally, you have to register this new View Helper using:
Using a partial script
This one seems to me a little bit longer, but it worth a try.
Basically, you need to set a partial script to your navigation using
setPartial()
method and you menu will be rendered through this partial.Afterwards, in your _nav.phtml you can render your menu as you wish. From this partial, you can access the menu variables using
$this->container
. Then, you can iterate through each page of your container, and display what you want.I know all of this seem pretty complicate for such a simple task, but unfortunately this is the only solution. Does anyone have a better idea?