Symfony2教程 - 生成Bundle

3

我对symfony2很新,但熟悉symfony。我正在进行symblog教程。目前进展顺利,但我在生成bundle方面遇到了一些困难?

教程指示运行以下命令:

php app/console generate:bundle --namespace=Blogger/BlogBundle --format=yml

完成后,它应在捆绑包中添加引用/生成代码。
  • app/AppKernel.php
  • app/config/routing.yml
然而它并没有添加任何东西?我有点困惑。控制台输出以下内容,但是代码中引用的捆绑包并没有生成在文件中。
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 [Blogger/BlogBundle]: 

1
请注意,此教程适用于sf2.0.x版本。您使用的是哪个版本? - j0k
2.1.7 - 可能我调用了错误的命令或者使用方法不正确? - Robbo_UK
Symfony的新版本与教程所期望的行为不同。 - Robbo_UK
4个回答

11
您可以在不需要互动的情况下使用它,那么它就不会询问您任何问题。

您可以在不需要互动的情况下使用它,那么它就不会询问您任何问题

php app/console generate:bundle --namespace=Blogger/BlogBundle --format=yml --no-interaction

这是最好的答案。非常简洁。教程应该有这个命令行。 - Robbo_UK

6

generate:bundle --help命令中得知:

如果您想禁用任何用户交互,请使用--no-interaction选项,但不要忘记传递所有必需的选项:

php app/console generate:bundle --namespace=Acme/BlogBundle --dir=src [--bundle-name=...] --no-interaction

我有针对这些长命令的Bash函数。

genbundle () {
    php app/console generate:bundle --namespace=$1/$2Bundle --bundle-name=$2Bundle --dir=src/ --format=yml
}

您可以像这样使用它:"genbundle Acme Blog",它将在Acme应用程序中创建一个BlogBundle。

1
如果我理解正确,您需要按照步骤回答问题来进行此过程。请回答所有问题,然后控制台会在创建包时告诉您何时完成。
注意:方括号中的值是当您只需按Enter键时,控制台将使用的默认值。

0

旧命令:

php app/console generate:bundle --namespace=Blogger/BlogBundle --format=yml --no-interaction

在新的Symfony版本3.1.4中,"app/console"已经不再起作用。 取而代之,在上述命令中添加"bin/console"

因此,新命令将是

php bin/console generate:bundle --namespace=Blogger/BlogBundle --format=yml --no-interaction

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接