KnpLabs / KnpMenuBundle

Object Oriented menus for your Symfony project.
http://knplabs.com
MIT License
1.4k stars 203 forks source link

Call to undefined method Knp\Menu\MenuItem::setCurrentUri() #344

Closed pasug closed 7 years ago

pasug commented 7 years ago

While updating symphony from 2.3 to 2.7, and after composer update, I am getting error as below

Fatal error: Call to undefined method Knp\Menu\MenuItem::setCurrentUri() in /var/www/fabric/production/releases/2017-05-09T094930/Symfony/src/Causecast/Bundle/CTGBundle/Menu/Builder.php on line 71

Fatal error: Uncaught exception 'Symfony\Component\Debug\Exception\UndefinedMethodException' with message 'Attempted to call an undefined method named "setCurrentUri" of class "Knp\Menu\MenuItem". Did you mean to call "setCurrent"?' in /var/www/fabric/production/releases/2017-05-09T094930/Symfony/src/Causecast/Bundle/CTGBundle/Menu/Builder.php:71 Stack trace: #0 {main} Next exception 'Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException' with message 'Circular reference detected for service "causecast_ctg.menu.top", path: "causecast_ctg.menu.top".' in /var/www/fabric/production/releases/2017-05-09T094930/Symfony/app/bootstrap.php.cache:2114 Stack trace: #0 /var/www/fabric/production/releases/vendor/knplabs/knp-menu-bundle/Provider/ContainerAwareProvider.php(25): Symfony\Component\DependencyInjection\Container->get('causecast_ctg.m...') #1 /var/www/fabric/production/releases/vendor/knplabs/knp-menu/src/Knp/Menu/Provider/ChainProvider.php(21): Knp\Bundle\MenuBundle\Provider\ContainerAwareProvid in /var/www/fabric/production/releases/2017-05-09T094930/Symfony/src/Causecast/Bundle/CTGBundle/Resources/views/layout.html.twig on line 235

Composer:

"require": {
        "php": ">=5.3.9",
        "symfony/symfony": "2.7",
        "doctrine/orm": "^2.4.8",
        "doctrine/doctrine-bundle": "~1.4",
        "symfony/assetic-bundle": "2.3.*",
        "symfony/swiftmailer-bundle": "2.3.*",
        "symfony/monolog-bundle": "2.4.*",
        "sensio/distribution-bundle": "~4.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "~2.0",
        "jms/security-extra-bundle": "1.5.*",
        "jms/di-extra-bundle": "1.8.*",
        "knplabs/knp-menu-bundle": "2.1.3",
        "sonata-project/cache-bundle": "^2.3",
        "sonata-project/block-bundle": "^3.3",
        "sonata-project/jquery-bundle": "1.8.*@dev",
        "sonata-project/exporter": "1.*",
        "sonata-project/user-bundle": "dev-pasu",
        "sonata-project/datagrid-bundle" : "^2.2",
        "sonata-project/doctrine-orm-admin-bundle": "^3.1",
        "sonata-project/easy-extends-bundle": "^2.1",
        "sonata-project/core-bundle": "3.3.0",
        "sonata-project/admin-bundle": "^3.15",
        "liip/imagine-bundle": "dev-master#043e6c27dbfce55b96b92645c8fa280c528526d0",
        "leaseweb/memcache-bundle": "1.1.2",
        "stof/doctrine-extensions-bundle": "1.1.*@dev",
        "staycassiopeia/redactor-character-count": "0.0.1"
    },

Few of the earlier suggestions refers to use knp-menu-bundle as 1.*.

Is it in the same state yet? I am not able to use knp-menu-bundle as 1.* since other packages are looking for higher version. Is there any alternative or fix for the same ?

This is in reference to previous issue. https://github.com/sonata-project/sandbox/issues/484

stof commented 7 years ago

Well, KnpMenu dropped the setCurrentUri method in 2.x, as we have better ways to mark an item as current.

The right solution is to stop using this method. Forcing to use the 1.x version was a workaround for cases where third-party packages were relying on this method. but here, the error seems to happen in your own code. So you should be able to migrate to the 2.x way.