【问题标题】:KnpMenuBundle and the proposed tutorial example: is something wrong?KnpMenuBundle 和建议的教程示例:有什么问题吗?
【发布时间】:2012-06-22 16:21:17
【问题描述】:

KNP MenuBundle 是一个 Symfony2 包,用于以非常动态的方式处理菜单。该捆绑包附带一个简单的教程示例,提供here。 在建议的示例中,在 Builder 类中,作者假设必须在 $menu 对象上调用函数 setCurrentUri()。但是,$menu 是 MenuItem 类的一个实例,它没有实现上述功能。

为了让答案自成一体,我报告了here提供的示例类的代码:

<?php
// src/Acme/DemoBundle/Menu/Builder.php
namespace Acme\DemoBundle\Menu;

use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAware;

class Builder extends ContainerAware
{
    public function mainMenu(FactoryInterface $factory, array $options)
    {
        $menu = $factory->createItem('root');
        $menu->setCurrentUri($this->container->get('request')->getRequestUri());

        $menu->addChild('Home', array('route' => 'homepage'));
        $menu->addChild('About Me', array(
            'route' => 'page_show',
            'routeParameters' => array('id' => 42)
        ));
        // ... add more children

        return $menu;
    }
}

PS:请注意,此示例中缺少一个重要的导入,为了完整起见,我将其报告如下:

use Symfony\Component\HttpFoundation\Request;

【问题讨论】:

    标签: symfony menu knpmenubundle


    【解决方案1】:

    我也在寻找文档更新,但作为临时解决方案,您可以在 deps 中设置版本,如下所示:

    [KnpMenu]
        git=https://github.com/KnpLabs/KnpMenu.git
        version=v1.1.2
    
    [KnpMenuBundle]
        git=https://github.com/KnpLabs/KnpMenuBundle.git
        target=/bundles/Knp/Bundle/MenuBundle
        version=v1.1.0
    

    【讨论】:

    • 我尝试安装该版本,但出现“不是 git 存储库”异常
    • 好的,现在可以了!你的回答没问题!我会接受的。 1.1.2 是不是最新版本?
    • 是的,1.1.2 是最新的标签,与捆绑包配合得很好。
    猜你喜欢
    • 1970-01-01
    • 2021-06-14
    • 2023-03-26
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-20
    相关资源
    最近更新 更多