Zend导航自定义渲染 [英] Zend Navigation Custom Rendering

查看:89
本文介绍了Zend导航自定义渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to create a custom navigation for zend navigation but i have two questions:

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

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

This is my code so far:

在控制器中:

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

提前感谢大家!

推荐答案

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') ?>

这是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;

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

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;

这篇关于Zend导航自定义渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆