简体   繁体   English

symfony2教程 - 生成包

[英]symfony2 tutorial - generate bundle

I am new to symfony2 but not to symfony. 我是symfony2的新手,但不是symfony。 I am currently doing the symblog tutorial . 我目前正在做symblog教程 Its going ok so far however I have come a little stuck on the generate bundle? 它到目前为止还不错,但是我对生成包有点卡住了吗?

The tutorial says to run the following command 该教程说要运行以下命令

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

After completing that it should add reference/generate code to the bundle in the 完成之后,它应该将引用/生成代码添加到包中

  • app/AppKernel.php 应用程序/ AppKernel.php
  • app/config/routing.yml 应用程序/配置/ routing.yml中

However it has not added anything?... I'm a bit confused? 但它没有添加任何东西?...我有点困惑? The console outputs the following but the code references to the bundle have not been generated in the files 控制台输出以下内容,但尚未在文件中生成对包的代码引用

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]: 

You can use this without interaction . 您无需互动即可使用此功能。 then it won't ask you anything 然后它不会问你什么

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

From generate:bundle --help 来自generate:bundle --help

If you want to disable any user interaction, use --no-interaction but don't forget to pass all needed options: 如果要禁用任何用户交互,请使用--no-interaction但不要忘记传递所有需要的选项:

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

I have bash functions for these long commands. 我有这些长命令的bash函数。

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

You can use it like this: "genbundle Acme Blog", It'll create a BlogBundle in the Acme app. 您可以像这样使用它:“genbundle Acme Blog”,它将在Acme应用程序中创建一个BlogBu​​ndle。

If I understood what's going on correctly, you have to go on the process. 如果我理解正确的是什么,你必须继续这个过程。 It's step-by-step where you answer the questions. 这是您回答问题的一步一步。 Keep answering everything asked, and then the console will tell when it created the bundle. 继续回答所有问题,然后控制台会告诉它何时创建了捆绑包。

Note: the value in [...] are the default value if you just press enter when the console asks you something. 注意:如果您在控制台询问某事时只按Enter键,则[...]中的值为默认值。

Old Command: 旧命令:

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

In new symfony version 3.1.4, "app/console" is no more working. 在新的symfony版本3.1.4中, “app / console”不再有效。 Instead add "bin/console" in above command 而是在上面的命令中添加“bin / console”

So the New command will be 所以新命令将是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM