Zend Navigation 自定义渲染

发布于 2025-01-05 04:42:36 字数 1050 浏览 0 评论 0原文

我正在尝试为 zend 导航创建自定义导航,但我有两个问题:

  1. 如何将变量传递给自定义部分 phtml,或者是否可能?
  2. 如何通过整个活动菜单树设置类?

到目前为止,这是我的代码:

在控制器中:

$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:

  1. How do i pass variables to custom partial phtml, or if it's possible?
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一世旳自豪 2025-01-12 04:42:36
echo $this->navigation($this->nav)->menu()->setPartial('menu.phtml')->render(); ?>

不太正确,你有正确的想法,但尝试

//This will pass a valid container to your partial with the $this->nav
echo $this->navigation()->menu()->renderPartial($this->nav,'menu.phtml') ?>

这里是 api:

public function renderPartial(Zend_Navigation_Container $container = null,
                                  $partial = null)

这也看起来有点奇怪:

$config = new Zend_Config($menu);
$nav = new Zend_Navigation();
$nav->addPages($config);
$this->view->nav = $nav;

我不认为 -> addPages() 是你想要的,我认为你需要的是:

//where $menu is the container and is config(.ini) object not .xml
//for xml use Zend_Config_Xml or Zend_Config_Json for JSON
$config = new Zend_Config($menu);
$nav = new Zend_Navigation($config);
//assign the container to the view
$this->view->nav = $nav;
echo $this->navigation($this->nav)->menu()->setPartial('menu.phtml')->render(); ?>

is not quite correct, you have the right idea but try

//This will pass a valid container to your partial with the $this->nav
echo $this->navigation()->menu()->renderPartial($this->nav,'menu.phtml') ?>

here is the api:

public function renderPartial(Zend_Navigation_Container $container = null,
                                  $partial = null)

also this bit looks a little wonky as well:

$config = new Zend_Config($menu);
$nav = new Zend_Navigation();
$nav->addPages($config);
$this->view->nav = $nav;

I don't think ->addPages() is what you want here, I think what you need is:

//where $menu is the container and is config(.ini) object not .xml
//for xml use Zend_Config_Xml or Zend_Config_Json for JSON
$config = new Zend_Config($menu);
$nav = new Zend_Navigation($config);
//assign the container to the view
$this->view->nav = $nav;
小…楫夜泊 2025-01-12 04:42:36

请参阅此处

如果使用 ACL 则将此行添加到有效的 ACL

if ($this->navigation()->accept($page))

其结果

...    
    foreach ( $iterator as $page ) {
        //VALID ACL
        if ($this->navigation()->accept($page)) {
            ...
            ...
        }
    }
    ..

See HERE

Add this line to valid ACL if use ACL

if ($this->navigation()->accept($page))

Its result

...    
    foreach ( $iterator as $page ) {
        //VALID ACL
        if ($this->navigation()->accept($page)) {
            ...
            ...
        }
    }
    ..
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文