0

Symfony:导入捆绑路由资源时出现问题

我正在尝试使用 Symfony 应用程序控制台生成一个包,

$ php app/console generate:bundle

但我不断收到错误

    Confirm automatic update of the Routing [yes]? 

导入捆绑路由资源:失败

该命令无法自动配置所有内容。
您必须手动进行以下更改。

Bundle PulsestormHelloworldBundle 已经被导入。

有谁知道如何解决这个问题?换句话说,此错误的常见原因是什么,以及应用程序控制台在执行Routing 的自动更新时具体在做什么。缺乏这一点,是否有一个理想的地方可以跳入源代码以开始调试黑客为什么会失败?

背景:我是一位经验丰富的程序员,但对 Symfony 开发不熟悉。我已经生成了一个新的捆绑包和一个教程。但是,我意识到我不小心使用注释格式而不是 yaml/yml 格式创建了一个包。不确定差异,我想重新生成捆绑包。去做这个

  1. 我从AppKernel

  2. 我使用脚本重新生成了app/bootstrap.php.cache文件build_bootstrap.php

  3. 我从生成它的文件夹中删除了我的包的源代码src(这个文件夹是空的)

但是,每当我执行generate:bundle命令步骤时,它总是以

Confirm automatic update of the Routing [yes]? 

导入捆绑路由资源:失败

该命令无法自动配置所有内容。
您必须手动进行以下更改。

Bundle PulsestormHelloworldBundle 已经被导入。

所以,我的假设是我的代码库中有一些来自上一代尝试的人工制品导致了这个错误,但我没有足够的 Symfonyt 经验来追踪这个问题。

我在下面包含了整个 CLI 交互,以防它有助于故障排除。

$ php app/console generate:bundle


  Welcome to the Symfony2 bundle generator  



Your application code must be written in bundles. This command helps
you generate them easily.

Each bundle is hosted under a namespace (like Acme/Bundle/BlogBundle).
The namespace should begin with a "vendor" name like your company name, your
project name, or your client name, followed by one or more optional category
sub-namespaces, and it should end with the bundle name itself
(which must have Bundle as a suffix).

See http://symfony.com/doc/current/cookbook/bundles/best_practices.html#index-1 for more
details on bundle naming conventions.

Use / instead of \  for the namespace delimiter to avoid any problem.

Bundle namespace: Pulsestorm/Bundle/HelloworldBundle

In your code, a bundle is often referenced by its name. It can be the
concatenation of all namespace parts but it's really up to you to come
up with a unique name (a good practice is to start with the vendor name).
Based on the namespace, we suggest PulsestormHelloworldBundle.

Bundle name [PulsestormHelloworldBundle]: 

The bundle can be generated anywhere. The suggested default directory uses
the standard conventions.

Target directory [/Users/alanstorm/Documents/github_oro/crm-application/src]: 

Determine the format to use for the generated configuration.

Configuration format (yml, xml, php, or annotation) [annotation]: yml

To help you get started faster, the command can generate some
code snippets for you.

Do you want to generate the whole directory structure [no]? yes


  Summary before generation  


You are going to generate a "Pulsestorm\Bundle\HelloworldBundle\PulsestormHelloworldBundle" bundle
in "/Users/alanstorm/Documents/github_oro/crm-application/src/" using the "yml" format.

Do you confirm generation [yes]? 


  Bundle generation  


Generating the bundle code: OK
Checking that the bundle is autoloaded: OK
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.                      


Bundle PulsestormHelloworldBundle is already imported.
4

1 回答 1

3

正如我所怀疑的,问题出在屏幕和键盘之间。虽然 Symfony 中的每个包都可能有自己的routing.yml文件,但在

app/config/routing.yml

该文件指向每个单独的捆绑包的路由文件。当您“导入捆绑路由资源”时,您正在向此文件添加一个配置条目。

#app/config/routing.yml
pulsestorm_helloworld:
    resource: "@PulsestormHelloworldBundle/Resources/config/routing.yml"
    prefix:   /

因为不知道这个app/config/routing.yml文件,所以之前添加的配置没去掉。这就是控制台应用程序一直在抱怨的问题。当我从主 routing.yml 文件中删除上述内容时,我可以干净地运行 Bundle 生成。

于 2013-06-22T18:55:54.973 回答