symfony2捆绑自动加载失败

问题描述 投票:2回答:7

我碰巧得到了创作的所有symfony问题......

我想创建一个新项目。

我复制'symfony2'文件夹,然后重命名:

 php app/console generate:bundle

它说:

  Generating the bundle code: OK
  Checking that the bundle is autoloaded: FAILED
  Confirm automatic update of your Kernel [yes]? 
  Enabling the bundle inside the Kernel: OK
  Confirm automatic update of the Routing [yes]? 
  Importing the bundle routing resource: FAILED

  The command was not able to configure everything automatically.  
  You must do the following changes manually.                      

  - Edit the composer.json file and register the bundle
  namespace in the "autoload" section:

  Bundle MddevPsavBundle is already imported.

为什么是这样?当我上次没有遇到那个问题时,我做了同样的命令?

我该如何解决这个问题呢?我应该在composer.json文件中添加什么?

我尝试了一些东西但是得到了:

  Fatal error: Class 'Mddev\PsavBundle\MddevPsavBundle' not found in
  /var/www/projetQ/app/AppKernel.php on line 22
symfony bundle
7个回答
2
投票

似乎您的bundle命名空间不遵循约定:http://symfony.com/doc/current/cookbook/bundles/best_practices.html#bundle-name

您应该使用Mddev\Bundle\MddevPsavBundleMddev\MddevPsavBundle作为bundle命名空间。


10
投票

如果您遇到问题:

The command was not able to configure everything automatically.  
You must do the following changes manually.

然后告诉你:

- Edit the composer.json file and register the bundle
namespace in the "autoload" section:

假设您已正确遵循bundle name conventions,那么您将需要:


将新包添加到composer.json文件中

"autoload": {
    "psr-0": {
        "currentbundle\\": "src/",
        "YOURNEWBUNDLE\\": "src/",            
    }
}

然后,您需要再次在composer上运行install

composer -n install --dev

然后,您应该将两个捆绑包自动加载


2
投票

我刚才遇到了这个问题。 app / console generate:bundle失败了自动加载检查并且没有创建src目录。我习惯于采用默认答案,我没注意到src目录指向缓存目录。

我输入正确的路径,一切都很顺利。

我想熟悉确实会引起蔑视。


0
投票

我得到了错误,因为在运行generate:bundle之前我没有安装composer。

一旦我安装了composer,再次尝试该命令(在删除创建的bundle文件和app / AppKernal.php中的代码之后)它立即就可以了


0
投票

当从命令行生成捆绑包时,生成器不会考虑捆绑包所在的目录,这可能会在向捆绑包添加供应商前缀时导致问题,您需要确保两件事情能够正常工作

  1. 检查AppKernel.php> registerBundles()中的命名空间
  2. 检查bundle类中的命名空间
  3. 运行composer update只是为了确保正确创建自动加载器

例如: - UserBundle.php中的namespace Acme\UserBundle;

|-----|
|    src
|       |
|      Acme
|          |
|        UserBundle
|               .
|               .
|           UserBundle.php

AppKernel.php里面有new Acme\UserBundle\UserBundle(),


0
投票

要修复此错误,必须在composer.json中添加此代码:

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

总是所有Bundles都在/src这个改变是我在Symfony 3.3.x的解决方案

问候


0
投票

在autoload中更改composer.json

"autoload": {
            "psr-4": {
                "Composer\\CaBundle\\": "src"
            }
        },

添加运行命令composer dumpautoload

© www.soinside.com 2019 - 2024. All rights reserved.