简体   繁体   中英

symfony2 tutorial - generate bundle

I am new to symfony2 but not to symfony. I am currently doing the symblog tutorial . 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
  • app/config/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

If you want to disable any user interaction, use --no-interaction but don't forget to pass all needed options:

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

I have bash functions for these long commands.

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.

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.

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. Instead add "bin/console" in above command

So the New command will be

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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