2017-08-11 133 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