Zend导航自定义渲染

时间:2012-02-13 12:17:17

标签: php zend-framework zend-navigation

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

  1. 如何将变量传递给自定义部分phtml,或者是否可能?
  2. 如何通过整个活动菜单树设置课程?
  3. 到目前为止,这是我的代码:

    在控制器中:

    $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>';
    

    提前感谢大家!

2 个答案:

答案 0 :(得分:4)

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;

我不认为 - &gt; 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;

答案 1 :(得分:2)

请参阅HERE

如果使用ACL

,请将此行添加到有效的ACL中
if ($this->navigation()->accept($page))

结果

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