Symfony2 - 奏鸣曲和 KnpMenu - setCurrentUri

Symfony2 - Sonata & KnpMenu - setCurrentUri

所以我想安装Sonata Admin Bundle and Sonata User Bundle。 根据他们的页面,AdminBundle requires KNPMenuBundle in version 2.* 所以我的 composer.json 看起来像这样:

"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "2.6.*",
    "doctrine/orm": "~2.2,>=2.2.3,<2.5",
    "doctrine/dbal": "<2.5",
    "doctrine/doctrine-bundle": "~1.2",
    "twig/extensions": "~1.0",
    "twbs/bootstrap": "~3",
    "components/jquery": "dev-master",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~3.0,>=3.0.12",
    "sensio/framework-extra-bundle": "~3.0,>=3.0.2",
    "incenteev/composer-parameter-handler": "~2.0",
    "friendsofsymfony/user-bundle": "1.3.*",
    "sonata-project/doctrine-orm-admin-bundle": "2.4.*@dev",
    "sonata-project/admin-bundle": "dev-master",
    "sonata-project/easy-extends-bundle": "^2.1",
    "sonata-project/user-bundle": "^2.2"
},

并且AppKernel.php像这样

$bundles = [
    new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
    new Symfony\Bundle\SecurityBundle\SecurityBundle(),
    new Symfony\Bundle\TwigBundle\TwigBundle(),
    new Symfony\Bundle\MonologBundle\MonologBundle(),
    new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
    new Symfony\Bundle\AsseticBundle\AsseticBundle(),
    new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
    new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
    new My\ProductBundle\MyPdBundle(),
    new FOS\UserBundle\FOSUserBundle(),
    new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
    new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
    new Sonata\CoreBundle\SonataCoreBundle(),
    new Sonata\BlockBundle\SonataBlockBundle(),
    new Knp\Bundle\MenuBundle\KnpMenuBundle(),
    new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),

    new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
    new Sonata\AdminBundle\SonataAdminBundle(),
    ];

但是当我尝试访问 mypage.local/app_dev.php/profile 时出现了这个错误:

Attempted to call method "setCurrentUri" on class "Knp\Menu\MenuItem".
Did you mean to call "setCurrent"?
500 Internal Server Error - UndefinedMethodException

in vendor/sonata-project/user-bundle/Block/ProfileMenuBlockService.php at line 91
$menu->setCurrentUri($settings['current_uri']);

堆栈中有很多信息表明 Sonata 在 1.3 版中需要 KnpMenuBundle 但正如我所写,在 dev-master bramch Sonata 中需要在版本 2 中使用 KnpMenuBndle。*

终于想通了!

如果您想使用 Sonata AdminPanel 和 Sonada UserPanel(带有 FOSUserBundle),这里是工作配置:

"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "2.6.*",
    "doctrine/orm": "~2.2,>=2.2.3,<2.5",
    "doctrine/dbal": "<2.5",
    "doctrine/doctrine-bundle": "~1.2",
    "twig/extensions": "~1.0",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~3.0,>=3.0.12",
    "sensio/framework-extra-bundle": "~3.0,>=3.0.2",
    "incenteev/composer-parameter-handler": "~2.0",
    "friendsofsymfony/user-bundle": "1.3.*@dev",
    "sonata-project/block-bundle": "2.3.*@dev",
    "sonata-project/easy-extends-bundle": "^2.1",
    "sonata-project/datagrid-bundle": "~2.2@dev",
    "sonata-project/admin-bundle": "~2.3@dev",
    "sonata-project/doctrine-orm-admin-bundle": "~2.3@dev",
    "stof/doctrine-extensions-bundle": "~1.1@dev",
    "sonata-project/user-bundle": "~2.3@dev"
},

您可以使用1.3版本的FOSUserBundle,但它只支持2.1版本的SF2。 FOS 1.3.* 2.6版本支持SF2

"friendsofsymfony/user-bundle": "1.3.*@dev"