Zend Navigation 自定义渲染
我正在尝试为 zend 导航创建自定义导航,但我有两个问题:
- 如何将变量传递给自定义部分 phtml,或者是否可能?
- 如何通过整个活动菜单树设置类?
到目前为止,这是我的代码:
在控制器中:
$config = new Zend_Config($menu);
$nav = new Zend_Navigation();
$nav->addPages($config);
$this->view->nav = $nav;
在视图中:
<?php echo $this->navigation($this->nav)->menu()->setPartial('menu.phtml')->render(); ?>
以及我的部分代码:
<?php
function genMenu($container)
{
foreach ($container as $page)
{
echo '<li>';
$href = $page->uri;
$target = '_self';
echo '<a href="' . $href . '" target="' . $target . '">' . $page->label . '</a>';
if (!empty($page->pages))
{
echo '<ul>';
genMenu($page->pages);
echo '</ul>';
}
echo '</li>';
}
}
echo '<ul>';
genMenu($this->container);
echo '</ul>';
提前感谢大家!
I'm trying to create a custom navigation for zend navigation but i have two questions:
- How do i pass variables to custom partial phtml, or if it's possible?
- How do i set a class trough the whole active menu tree?
This is my code so far:
in the controller:
$config = new Zend_Config($menu);
$nav = new Zend_Navigation();
$nav->addPages($config);
$this->view->nav = $nav;
in the view:
<?php echo $this->navigation($this->nav)->menu()->setPartial('menu.phtml')->render(); ?>
and my partial:
<?php
function genMenu($container)
{
foreach ($container as $page)
{
echo '<li>';
$href = $page->uri;
$target = '_self';
echo '<a href="' . $href . '" target="' . $target . '">' . $page->label . '</a>';
if (!empty($page->pages))
{
echo '<ul>';
genMenu($page->pages);
echo '</ul>';
}
echo '</li>';
}
}
echo '<ul>';
genMenu($this->container);
echo '</ul>';
Thanks everyone in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不太正确,你有正确的想法,但尝试
这里是 api:
这也看起来有点奇怪:
我不认为 -> addPages() 是你想要的,我认为你需要的是:
is not quite correct, you have the right idea but try
here is the api:
also this bit looks a little wonky as well:
I don't think ->addPages() is what you want here, I think what you need is:
请参阅此处
如果使用 ACL 则将此行添加到有效的 ACL
其结果
See HERE
Add this line to valid ACL if use ACL
Its result