Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to method setCurrentUri fails in Symfony/SonataUserBundle setup

I am trying to set up Symfony with the SonataUserBundle. User registration and login works fine. When I try to call up the /profile view, however I get the following error:

Attempted to call method "setCurrentUri" on class "Knp\Menu\MenuItem" in F:\<my project path>\vendor\sonata-project\user-bundle\Block\ProfileMenuBlockService.php line 91. Did you mean to call: "setCurrent"?

The last notice in the "event list" before the error is

INFO - [cms::renderBlock] block.id=53, block.type=sonata.user.block.menu

Has anyone encountered this error before and can provide information on how to resolve it?

TIA Matt

like image 211
matt_jay Avatar asked Aug 07 '14 17:08

matt_jay


People also ask

How to retry failed HTTP requests in Symfony?

Sometimes, requests fail because of network issues or temporary server errors. Symfony's HttpClient allows to retry failed requests automatically using the retry_failed option.

How do I choose a specific service in Symfony?

If you use scoped clients in the Symfony framework, you must use any of the methods defined by Symfony to choose a specific service . Each client has a unique service named after its configuration. Each scoped client also defines a corresponding named autowiring alias.

How to use GitHub client in Symfony autowiring?

If you use for example Symfony\Contracts\HttpClient\HttpClientInterface $githubClient as the type and name of an argument, autowiring will inject the github.client service into your autowired classes. Read the base_uri option docs to learn the rules applied when merging relative URIs into the base URI of the scoped client.

How do I disable the return clone feature in Symfony?

If you don't want a method with a PHP 8 static return type and a @required annotation to behave as a wither, you can add a @return $this annotation to disable the returns clone feature. This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license. Symfony 6.0 is backed by SensioLabs .


Video Answer


2 Answers

What versions of KnpMenu and SonataBlockBundle are you using? Please check your composer.json to be sure.

The setCurrentUri method has been deprecated as of KnpMenu v. 2.0, and the composer.json of SonataBlockBundle does not require KnpMenu anywhere but in dev install. So, this leads to a possibility that you could have required a fresher version of knplabs/knp-menu-bundle that is not yet supported by Sonata bundle.

Try requiring knplabs/knp-menu-bundle in 1.1.x:

{
    ...
    "require": {
        "knplabs/knp-menu-bundle": "~1.1"
    },
    ...
}
like image 147
kix Avatar answered Oct 16 '22 20:10

kix


I encountered the same problem, but downgrade to Knpmenu version 1 is not possible for our project. Because of some code update the June 16th, it is now possible to use Sonata User Bundle and Knp Menu Version 2.

Please, have a look on my composer.json :

"require": {
    "php": ">=5.3.9",
    "symfony/symfony": "2.7.*",
    "doctrine/orm": "^2.4.8",
    "doctrine/doctrine-bundle": "~1.4",
    "doctrine/doctrine-fixtures-bundle": "dev-master",
    "doctrine/migrations": "dev-master",
    "doctrine/doctrine-migrations-bundle": "dev-master",
    "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",
    "friendsofsymfony/user-bundle": "~1.3",
    "friendsofsymfony/message-bundle": "^1.2",
    "sonata-project/admin-bundle": "^2.3",
    "sonata-project/doctrine-orm-admin-bundle": "^2.3",
    "sonata-project/easy-extends-bundle": "^2.1",
    "sonata-project/user-bundle": "dev-master",
    "sonata-project/datagrid-bundle": "dev-master",
    "sonata-project/block-bundle": "~2.2,>=2.2.7,<2.3",
    "sonata-project/exporter": "^1.4",
    "sonata-project/intl-bundle": "^2.2",
    "knplabs/knp-menu-bundle": "~2.0",
    "knplabs/knp-menu": "~2.0"
},

As you can see, sonata-project/user-bundle is under dev-master version and I had to add sonata-project/datagrid-bundle in dev-master

Hope to help developpers who want want to preserve KnpMenu V2 !

like image 38
Alexandre Tranchant Avatar answered Oct 16 '22 19:10

Alexandre Tranchant