0

在将 symfony 从 2.2 更新到 2.3 之后,我的所有页面和脚本中都出现了新的 stange 错误:

已弃用: Knp\Menu\Silex\Voter\RouteVoter 由于命名空间而被弃用,请改用 Knp\Menu\Matcher\Voter\RouteVoter。在第 20 行的 \vendor\knplabs\knp-menu\src\Knp\Menu\Silex\Voter\RouteVoter.php

已弃用: Knp\Menu\Silex\RoutingExtension 已弃用,请改用 Knp\Menu\Integration\Symfony\RoutingExtension。在第 15 行的 \vendor\knplabs\knp-menu\src\Knp\Menu\Silex\RoutingExtension.php

我该如何解决这个问题?我在网上找不到答案。
先感谢您

这是我的 composer.json :

{
    "name": "symfony/framework-standard-edition",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.3.*",
        "doctrine/orm": ">=2.2.3,<2.4-dev",
        "doctrine/doctrine-bundle": "1.2.*",
        "twig/extensions": "1.0.*",
        "symfony/assetic-bundle": "2.3.*",
        "symfony/swiftmailer-bundle": "2.3.*",
        "symfony/monolog-bundle": "2.3.*",
        "sensio/distribution-bundle": "2.3.*",
        "sensio/framework-extra-bundle": "2.3.*",
        "sensio/generator-bundle": "2.3.*",
        "incenteev/composer-parameter-handler": "~2.0",
    "genemu/form-bundle": "2.1.*",
        "jms/security-extra-bundle": "1.5.*",
        "jms/di-extra-bundle": "1.4.*",
        "phpunit/phpunit": "3.7.*",
    "doctrine/data-fixtures": "@dev",
    "friendsofsymfony/user-bundle": "~2.0@dev",
    "stof/doctrine-extensions-bundle": "dev-master",
        "knplabs/gaufrette": "0.2.*@dev",
        "knplabs/knp-gaufrette-bundle":          "dev-master",
    "jms/serializer-bundle":                 "0.13.*@dev",
        "amazonwebservices/aws-sdk-for-php":     "dev-master",
        "punkave/symfony2-file-uploader-bundle": "dev-master",
        "oneup/uploader-bundle":                 "dev-master",
        "knplabs/knp-paginator-bundle":          "dev-master",
        "jms/debugging-bundle":                  "dev-master",
        "winzou/console-bundle":                 "dev-master",
        "elao/web-profiler-extra-bundle" :       "dev-master",
        "cybernox/amazon-webservices-bundle":    ">=1.5.4",
        "genemu/form-bundle":                    "2.2.*",
    "escapestudios/wsse-authentication-bundle": "2.3.x-dev",
        "rezzza/flickr-bundle":                  "1.0.*@dev",
        "knplabs/knp-menu-bundle":               "dev-master",
        "genemu/form-bundle":                    "2.1.*",
        "leaseweb/api-caller-bundle":        "*",
        "eo/honeypot-bundle":                    "dev-master"        
    },
    "scripts": {
        "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"
        ],
        "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"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "minimum-stability": "alpha",
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        }, 
        "branch-alias": {
            "dev-master": "2.3-dev"
        }
    }
}

和我的菜单生成器:

namespace ...\Menu;

use Knp\Menu\Matcher\Matcher;
use Knp\Menu\MenuFactory;
use Knp\Menu\Renderer\ListRenderer;

use Symfony\Component\DependencyInjection\ContainerAware;

class Builder extends ContainerAware
{
    public function mainMenu(MenuFactory $factory, array $options)
    {
        $menu = $factory->createItem('root');

        $menu->addChild('Dashboard', array(
                        'route' => 'dashboard' )); 
        $menu->addChild('Color Scheme', array(
                        'uri' => 'slidescheme' ));
        $menu->addChild('Questionnnaires', array(
                        'uri' => 'questionnaire_manage' ));
        // ... add more children

        return $menu;
    }
}
4

2 回答 2

1

在开发过程中更新你的 symfony 版本不是一个好主意。实际上,升级您在代码中使用的任何捆绑软件都是一个坏主意(总是有例外,但这是一般规则)。

在您的情况下,该捆绑包已在此新版本中进行了重构,因此现在它与您编写的代码不兼容。恐怕你只有两种选择:

  • 使您的代码适应新的要求
  • 或者再次更改您的作曲家以使用 symfony 2.2 并运行composer update

如果您已经编写了多行代码,我强烈建议您使用第二种选择。

于 2014-06-30T08:26:57.257 回答
1

问题是您使用的是 knplabs/menu 的开发版本。从以下位置编辑您的作曲家文件:

"knplabs/knp-menu-bundle":               "dev-master",

至:

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

并且错误消息将消失。请注意,如果您实际上正在使用knplabs/menu 的开发功能(如MatcherVoter),则这些功能将不再可用。但是 Symfony 无论如何都不需要它们。

于 2014-07-02T13:52:19.583 回答