2017-08-11 132 views
-1

当我产生新的捆绑在symfony中2,当我在吃午饭浏览器的项目,我有这样的错误:生成新的捆绑

的ClassNotFoundException在AppKernel.php线19: 尝试从命名空间加载类“TagBundle”“测试\ TagBundle”。 您忘记了“test \ TagBundle \ TagBundle”的“使用”语句吗?

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 Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), 
       new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), 
       new AppBundle\AppBundle(), 
       new test\TagBundle\TagBundle(), 
      ); 

      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": "root/tagproject", 
     "license": "proprietary", 
     "type": "project", 
     "autoload": { 
      "psr-4": { 
       "AppBundle\\": "src/AppBundle" 
      }, 
      "classmap": [ 
       "app/AppKernel.php", 
       "app/AppCache.php" 
      ] 
     }, 
     "autoload-dev": { 
      "files": [ 
       "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" 
      ] 
     }, 
     "require": { 
      "php": ">=5.3.9", 
      "doctrine/doctrine-bundle": "~1.4", 
      "doctrine/orm": "^2.4.8", 
      "incenteev/composer-parameter-handler": "~2.0", 
      "sensio/distribution-bundle": "~4.0", 
      "sensio/framework-extra-bundle": "^3.0.2", 
      "symfony/monolog-bundle": "^3.0.2", 
      "symfony/swiftmailer-bundle": "~2.3,>=2.3.10", 
      "symfony/symfony": "2.8.*", 
      "twig/twig": "^1.0||^2.0" 
     }, 
     "require-dev": { 
      "sensio/generator-bundle": "~3.0", 
      "symfony/phpunit-bridge": "~2.7" 
     }, 
     "scripts": { 
      "symfony-scripts": [ 
       "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-install-cmd": [ 
       "@symfony-scripts" 
      ], 
      "post-update-cmd": [ 
       "@symfony-scripts" 
      ] 
     }, 
     "config": { 
      "bin-dir": "bin", 
      "sort-packages": true 
     }, 
     "extra": { 
      "symfony-app-dir": "app", 
      "symfony-web-dir": "web", 
      "symfony-assets-install": "relative", 
      "incenteev-parameters": { 
       "file": "app/config/parameters.yml" 
      }, 
      "branch-alias": null 
     } 
    } 

而在终端Ubuntu的我有这样的消息:

命令无法配置一切都自动。
您需要手动进行以下更改。

  • 编辑composer.json文件和 “自动加载” 部分中注册捆绑 命名空间:
+0

[包创建后Symfony3的ClassNotFoundException]的可能的复制(https://stackoverflow.com/questions/44946911/symfony3-classnotfoundexception-after-bundle-creation) –

回答

0

更新你这样的composer.json文件....替换 “NewBundle” 与你的包的名字。

"autoload": { 
    "psr-4": { 
     "AppBundle\\": "src/AppBundle", 
     "NewBundle\\": "src/NewBundle" 
    }, 
    "classmap": [ "app/AppKernel.php", "app/AppCache.php" ] 
}, 

奔跑;

composer dumpautoload 

您现在可以启动服务器了。

+0

好感谢主,但是如何错误!现在当我生成新的捆绑项目工作 – devit2017