Search code examples
phpsymfonysonata-adminsymfony-sonatasonata-user-bundle

Symfony2 - Sonata & KnpMenu - setCurrentUri


So I want to install Sonata Admin Bundle and Sonata User Bundle. According to their page, AdminBundle requires KNPMenuBundle in version 2.* So my composer.json looks like this:

"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"
},

And AppKernel.php like this

$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(),
    ];

But when I try to visit mypage.local/app_dev.php/profile I've got this error:

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']);

There is a lot of information in stack that Sonata requires KnpMenuBundle in version 1.3 but as I wrote, In dev-master bramch Sonata requires KnpMenuBndle in version 2.*


Solution

  • Finally, I figured it out!

    If you want to use Sonata AdminPanel & Sonada UserPanel (with FOSUserBundle) here is working configuration:

    "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"
    },
    

    You can use 1.3 version of FOSUserBundle but it supports only SF2 in 2.1 version. FOS 1.3.* supports SF2 in 2.6 version.

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