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

时间:2015-09-22 22:21:36

标签: php symfony fosuserbundle sonata-user-bundle knpmenubundle

我试图配置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"
        }
    }
}

2 个答案:

答案 0 :(得分:2)

您正在使用的是KnpMenu和SonataBlockBundle的帽子版本吗?请检查你的composer.json以确定。

自KnpMenu v.2.0起,setCurrentUri方法已被弃用,而SonataBlockBundle的composer.json在dev安装中不需要任何地方使用KnpMenu。因此,这可能会导致您需要更新版的knata / knp-menu-bundle,而Sonata捆绑包尚不支持。

尝试在1.1.x中使用knplabs / knp-menu-bundle:

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

答案 1 :(得分:2)

我遇到了同样的问题但是我们的项目无法降级到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

希望能帮到你!