【问题标题】:ClassNotFoundException in AppKernel.php line 25:AppKernel.php 第 25 行中的 ClassNotFoundException:
【发布时间】:2016-09-06 12:16:20
【问题描述】:

您好,当我尝试加载我的 symfony 2 应用程序时,会出现这个问题,

AppKernel.php 第 25 行中的 ClassNotFoundException:尝试从命名空间“Sonata\DoctrineORMAdminBundle”加载类“SonataDoctrineORMAdminBundle”。 您是否忘记了另一个命名空间的“使用”语句?

这是我的 AppKernel.php 文件,

    <?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new AppBundle\AppBundle(),
            new kcc\AdminBundle\kccAdminBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle(),
            new Sonata\CoreBundle\SonataCoreBundle(),
            new Sonata\BlockBundle\SonataBlockBundle(),
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
            new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
            new Sonata\AdminBundle\SonataAdminBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
    }
}

这个 composer.json 文件,

{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
    "psr-4": {
        "": "src/",
        "Sonata\\DoctrineORMAdminBundle\\": ""
    }
},
"require": {
    "php": ">=5.3.9",
    "symfony/symfony": "2.7.*",
    "doctrine/orm": "^2.4.8",
    "doctrine/doctrine-bundle": "~1.4",
    "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",
    "jms/serializer-bundle": "*",
    "weaverryan/derp-dangerzone": "dev-master",
    "vimuths123/menucreator": "dev-master",
    "sonata-project/admin-bundle": "^3.0",
    "sonata-project/doctrine-orm-admin-bundle": "^3.0",
    "sensio/generator-bundle": "2.3.*",
    "sonata-project/user-bundle": "^2.2",
    "friendsofsymfony/rest-bundle": "^1.7",
    "nelmio/api-doc-bundle": "^2.12",
    "sonata-project/core-bundle": "^3.0"
},
"require-dev": {
    "symfony/phpunit-bridge": "~2.7"
},
"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",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
    ],
    "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::prepareDeploymentTarget"
    ]
},
"config": {
    "bin-dir": "bin",
    "platform": {
        "php": "5.3.9"
    }
},
"extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "symfony-assets-install": "relative",
    "incenteev-parameters": {
        "file": "app/config/parameters.yml"
    },
    "branch-alias": {
        "dev-master": "2.7-dev"
    }
},
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/vimuths123/menucreator"
    }
]

}

我也尝试更新作曲家,但由于这个问题也无法更新

【问题讨论】:

  • 要更新内核,注释掉 AppKernel 中的类,然后更新。
  • 真的很抱歉,但仍然遇到问题Problem 1 - Installation request for sonata-project/doctrine-orm-admin-bundle ^3.0 -&gt; satisfiable by sonata-project/doctrine-orm-admin-bundle[3.0.0]. - sonata-project/doctrine-orm-admin-bundle 3.0.0 requires sonata-project/adm in-bundle ^3.0 -&gt; no matching package found.
  • 尝试在 composer.json 中添加 sonata-project/admin-bundle ^3.0 然后
  • 在您的脚本中尝试在顶部添加类似这样的内容来导入类:使用 Sonata\DoctrineORMAdminBundle\NAME_OF_THE_CLASS 想法是在您能够使用之前导入类它。 Autoloader 会解决这个问题。

标签: php symfony


【解决方案1】:

首先要做的事情。您确定您的 composer.json 文件包含以下标记为

的条目吗?
        "require": {
        "php": "^5.3 || ^7.0",
            "doctrine/orm": "^2.3",
            "symfony/form": "^2.3 || ^3.0",
            "symfony/security": "^2.3 || ^3.0",
            "symfony/console": "^2.3 || ^3.0",
            "symfony/doctrine-bridge": "^2.2 || ^3.0",
            "symfony/framework-bundle": "^2.2 || ^3.0",
            "symfony/security-acl": "^2.2 || ^3.0",
            "sonata-project/exporter": "^1.3.1",
            "sonata-project/admin-bundle": "^3.0",    // <== IMPORTANT
            "sonata-project/core-bundle": "^3.0"      // <== IMPORTANT
        },
        "require-dev": {
        "simplethings/entity-audit-bundle": "~0.1",
            "symfony/phpunit-bridge": "^2.7 || ^3.0"
        },
        "suggest": {
        "simplethings/entity-audit-bundle": "If you want to support for versioning of entities and their associations."
        },
        "provide": {
        "sonata-project/admin-bundle-persistency-layer": "1.0.0"
        },
        "autoload": {
        "psr-4": { "Sonata\\DoctrineORMAdminBundle\\": "" }  // <== GOOD TO ADD
        },

【讨论】:

  • 添加了文件,但似乎仍然无法正常工作。真对不起。我更新了新的 composer.json 文件
  • 你能告诉我们上下文吗?我的意思是只需将导入语句复制并粘贴到控制器中
  • 我没有使用控制器,因为我正在使用奏鸣曲管理员......而且我认为对于所有页面,这个问题仍然存在
【解决方案2】:

因为它写在documentation中,你必须通过composer安装SonataDoctrineORMAdminBundle

composer require sonata-project/doctrine-orm-admin-bundle

如果您关注instructions on the symfony page,它可能会有所帮助。

【讨论】:

    【解决方案3】:

    只需运行此命令

    composer install/update
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-26
      • 2017-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-08
      • 2013-07-09
      • 2016-11-09
      相关资源
      最近更新 更多