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

Posted

技术标签:

【中文标题】试图调用类“Knp\\Menu\\MenuItem”的名为“setCurrentUri”的未定义方法【英文标题】:Attempted to call an undefined method named "setCurrentUri" of class "Knp\Menu\MenuItem"试图调用类“Knp\Menu\MenuItem”的名为“setCurrentUri”的未定义方法 【发布时间】:2015-12-20 02:01:32 【问题描述】:

我正在尝试配置 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"
        
    

【问题讨论】:

我的错误仍然在这里堆积,请有人可以帮助我吗?谢谢 【参考方案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

希望能帮到你!

【讨论】:

【参考方案2】:

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

自 KnpMenu v. 2.0 起,setCurrentUri 方法已被弃用,并且 SonataBlockBundle 的 composer.json 在任何地方都不需要 KnpMenu,除非在开发安装中。因此,这导致您可能需要一个新版本的 knplabs/knp-menu-bundle,而 Sonata 捆绑包尚不支持。

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


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

【讨论】:

我正在使用:“sonata-project/block-bundle”:“~2.3@dev”和“knplabs/knp-menu-bundle”:“~2.0”。我尝试了 knp 菜单包的“~1.1”版本,但它不起作用当我尝试更新作曲家时出现错误。 我很惊讶只有 (Ralph Melhem) 能够在这个论坛上帮助我。因为这个论坛上有很多人在编程方面具有良好的计算机技能。谢谢拉尔夫·梅尔海姆。要修复我的错误,您应该使用以下不同版本的捆绑包:“knplabs/knp-menu-bundle”:“~2.0”、“sonata-project/user-bundle”:“2.3.*@dev”、“sonata” -project/block-bundle": "~2.3@dev", "sonata-project/admin-bundle": "~2.4@dev", @Dario 很高兴我能帮到你,请将我的答案标记为正确的;干杯

以上是关于试图调用类“Knp\Menu\MenuItem”的名为“setCurrentUri”的未定义方法的主要内容,如果未能解决你的问题,请参考以下文章

YAMLException:找不到类试图调用不在模型包中的类的构造函数

im是c ++的新手,我试图调用make以2个类作为其参数的类构造函数

试图在另一个类函数中使用成员类函数

Mockito:试图监视方法正在调用原始方法

试图了解模板类是如何工作的

C ++试图通过getline函数为函数调用获取用户输入值