试图调用名为 "setCurrentUri" 的未定义方法 class "Knp\Menu\MenuItem"

Attempted to call an undefined method named "setCurrentUri" of class "Knp\Menu\MenuItem"

我正在尝试配置 sonataUserBundle 和 fosUserBundle。当我尝试访问我的个人资料页面时,出现此错误:

    Attempted to call an undefined method named "setCurrentUri" of class "Knp\Menu\MenuItem".
Did you mean to call "setCurrent"? 

在我的 composer.json 中有这个版本的 "knplabs/knp-menu-bundle": "~2.0",

我降级到版本 "knplabs/knp-menu-bundle":“~1.1”。但是当我尝试更新作曲家时,我收到一条错误消息:

Problem 1
    - sonata-project/admin-bundle 2.4.x-dev requires knplabs/knp-menu-bundle >=2
.0,<3.0.0 -> no matching package found.
    - sonata-project/admin-bundle 2.4.x-dev requires knplabs/knp-menu >=2.0,<3.0
 -> no matching package found.
    - Installation request for sonata-project/admin-bundle ~2.4@dev -> satisfiab
le by sonata-project/admin-bundle[2.4.x-dev].

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your min
imum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> f
or more details.

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further commo
n problems.

有人知道如何解决这个错误吗?

Call to method setCurrentUri fails in Symfony/SonataUserBundle setup

谢谢

{
    "name": "symfony/framework-standard-edition",
    "license": "MIT",
    "type": "project",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/", "SymfonyStandard": "app/" }

    },
    "require": {
        "php": ">=5.3.9",
        "symfony/symfony": "2.7.*",
        "doctrine/orm": "~2.2,>=2.2.3,<2.5",
        "doctrine/dbal": "<2.5",
        "doctrine/doctrine-bundle": "~1.4",
        "twig/extensions": "~1.0",
        "symfony/assetic-bundle": "2.6.0",
        "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",
        "leafo/lessphp": "*",
        "twitter/bootstrap": "*",
        "mremi/contact-bundle": "dev-master",
        "symfony/twig-bridge": "2.3.*",
        "genemu/form-bundle": "2.2.*",
        "components/jquery":"dev-master",
        "friendsofsymfony/user-bundle": "~1.3",
        "hwi/oauth-bundle": "0.4.*@dev",

        "sonata-project/user-bundle": "2.2.4",
        "sonata-project/core-bundle":  "~2.3@dev,>=2.3.1",
        "sonata-project/block-bundle": "~2.3@dev",
        "sonata-project/page-bundle": "~2.3",
        "symfony-cmf/routing-bundle": "~1.1",
        "knplabs/knp-menu-bundle":  "~2.0",
        "sonata-project/admin-bundle": "~2.4@dev",
        "sonata-project/doctrine-orm-admin-bundle":  "~2.4@dev",
        "sonata-project/easy-extends-bundle": "~2.1"

    },
    "require-dev": {
        "sensio/generator-bundle": "~2.3"
    },
    "scripts": {
        "post-root-package-install": [
            "SymfonyStandard\Composer::hookRootPackageInstall"
        ],
        "post-install-cmd": [
            "Incenteev\ParameterHandler\ScriptHandler::buildParameters",
            "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
            "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
            "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
            "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
            "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::removeSymfonyStandardFiles"
        ],
        "post-update-cmd": [
            "Incenteev\ParameterHandler\ScriptHandler::buildParameters",
            "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
            "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
            "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
            "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
            "Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::removeSymfonyStandardFiles"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "symfony-assets-install": "relative",
        "symfony-assets-install":"symlink",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "2.7-dev"
        }
    }
}

您使用的是 KnpMenu 和 SonataBlockBundle 的哪个版本?请检查您的 composer.json 以确定。

从 KnpMenu v.2.0 开始,setCurrentUri 方法已被弃用,SonataBlockBundle 的 composer.json 除了在开发安装中以外的任何地方都不需要 KnpMenu。因此,这可能会导致您可能需要更新版本的 knplabs/knp-menu-bundle,而 Sonata 捆绑包尚不支持该版本。

尝试在 1 中要求 knplabs/knp-menu-bundle。1.x:

{
...
"require": {
    "knplabs/knp-menu-bundle": "~1.1"
},
...
}

我遇到了同样的问题,但我们的项目无法降级到 Knpmenu 版本 1。由于 some code update the June 16th,我们现在可以使用 Sonata User Bundle 和 Knp Menu Version 2。

拜托,看看我的 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"
},

如你所见,sonata-project/user-bundle 在 dev-master 版本下,我不得不在 dev-master

中添加 sonata-project/datagrid-bundle

希望能帮到你!