Archives


Master Symfony2 fundamentals

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Discover the SensioLabs Support

Access to the SensioLabs Competency Center for an exclusive and tailor-made support on Symfony
sensiolabs.com

Fabien Potencier
Symfony2: Getting Easier - Interactive Generators
by Fabien Potencier – June 22, 2011 – 72 comments

Some people keep thinking that Symfony2 requires a lot of upfront configuration... even more than symfony1. It took me a while to understand why people would think so as there is nothing to configure in Symfony2 if you are using the Symfony Standard Edition, except the database settings if you need one (and this can be done from the browser).

But recently, I saw the light: people are talking about creating new bundles, new Doctrine entities, new CRUD controllers, ... symfony1 has generators for all those things, but until now, Symfony2 was not very good at generating code. Well, that's "fixed" now, thanks to the new GeneratorBundle. The bundle is included by default in Symfony SE (as of 2.0.0 RC1 which will be released on June 24th) and it knows how to generate bundles, forms, Doctrine entities, and simple CRUD controllers to get you started even faster.

The generators are even better than the ones in symfony1 as you can use them interactively; answer some questions and Symfony2 takes care of everything for you:

This screencast requires a more recent version of the Adobe Flash Player to display. Please update your version of the Adobe Flash Player.

The code is quite new and probably comes with a lot of bugs. Let's enhance it in the coming weeks!

Comments RSS

  • gravatar
    #1 Andy said on the 2011/06/22 at 11:52
    Horrar!

    All that was missing from SF2. SF2 feels so much more 'right', but I've kept with SF1.4 for most tasks because it was just that much quicker to work with.
  • gravatar
    #2 Stepan Tanasiychuk said on the 2011/06/22 at 11:59
    Very nice!

    It generates tests for entities and controllers?
  • gravatar
    #3 tomtomsen said on the 2011/06/22 at 12:01
    <3
  • gravatar
    #4 Hugo Hamon said on the 2011/06/22 at 12:04
    @Stephan it generates a stub test file. You have to complete it by yourself but the code is commented and it's almost functional. We can't generate a complete test file as we can't know how to fill the form with data. For example, it's impossible to know if a "username" field must be filled with an email address or a string or something else.
  • gravatar
    #5 Francesco levorato said on the 2011/06/22 at 12:06
    I am in love. Congrats to the core team :)
  • gravatar
    #6 Tobias Sjösten said on the 2011/06/22 at 12:08
    That's great news! I really liked this functionality in 1.4 and am looking forward to using it again in Symfony2.

    Is it possible to not use it interactively, but to pass all parameters in the command?

    Also when working with Symfony CLI I recommend checking out my bash script to make that bit easier: http://vvv.tobiassjosten.net/symfony/symfony2-cli-bash-script
  • gravatar
    #7 Edgar said on the 2011/06/22 at 12:10
    "The bundle is included by default in Symfony SE (as of 2.0.0 RC1 which will be released on June 24th) "

    Great news! 2 days left :D
  • gravatar
    #8 Fabien said on the 2011/06/22 at 12:10
    @Tobias Sjösten: Yes, you can use the commands without any interaction by passing the `--no-interaction` option. Also, you can pass some options on the command line and the values will be used as the default when interacting with the user.
  • gravatar
    #9 Sergey said on the 2011/06/22 at 12:11
    Where is a video ? I see just black player
  • gravatar
    #10 Inophage said on the 2011/06/22 at 12:11
    Nice. Good job.
  • gravatar
    #11 Joseph said on the 2011/06/22 at 12:16
    Hi,

    Your Generator Bundle looks great, good job Fabien !! I will testing it...
  • gravatar
    #12 Felds Liscia said on the 2011/06/22 at 12:16
    This will be useful not only for the newcomers.
    Generated code is a great way to standardize the code in Symfony1 and sure it will be true for Symfony2 too.

    Thank you very much!
  • gravatar
    #13 Jérémy said on the 2011/06/22 at 12:22
    Great ! we can finally be productive with SF2 :)
  • gravatar
    #14 Waldo menkveld said on the 2011/06/22 at 12:32
    Great news about RC1 coming in 2 days! I am really looking forward to test the new generator bundle.
  • gravatar
    #15 Fabian Spillner said on the 2011/06/22 at 12:33
    Amazing! This rocks!!!
  • gravatar
    #16 shakir said on the 2011/06/22 at 12:41
    Greaaat !
  • gravatar
    #17 Emmanuel PEREIRA said on the 2011/06/22 at 12:46
    And then there was light...
    Thanks a lot
  • gravatar
    #18 mhauri said on the 2011/06/22 at 13:36
    Looks Amazing!
    I'm a Symfony2 newcomer, and i guess this makes my life easier.
  • gravatar
    #19 Michael Kahle said on the 2011/06/22 at 13:59
    Great !!
  • gravatar
    #20 slem said on the 2011/06/22 at 14:16
    Great news! :) Great work!
  • gravatar
    #21 Vazgen said on the 2011/06/22 at 14:17
    Great!!!, I was waiting for this.
  • gravatar
    #22 Ryan Weaver said on the 2011/06/22 at 14:21
    Wow, this is the killer feature of Symfony2, and something I've wanted for a long time. Really well done!
  • gravatar
    #23 Pierre Spring said on the 2011/06/22 at 14:50
    Looks great. Looking forward to using it!
  • gravatar
    #24 Duane Gran said on the 2011/06/22 at 15:04
    Bravo! This really makes it easier to get started with the framework.
  • gravatar
    #25 Vincent said on the 2011/06/22 at 15:11
    Video was so fast, I couldn't see all the features ! Need to pause a lot...

    Great screencast and great job !
  • gravatar
    #26 Pedro said on the 2011/06/22 at 15:20
    Great news!!!
  • gravatar
    #27 Dmitry said on the 2011/06/22 at 15:21
    Excellent! This is the right thing, it reduces the amount of routine work.

    I have an idea, which could further increase the attractiveness of Symfony2. How about a a web interface to these generators? You already have awesome profiler.
  • gravatar
    #28 lexterikane said on the 2011/06/22 at 15:24
    Nice job there, really interesting stuff
  • gravatar
    #29 Xevi said on the 2011/06/22 at 16:57
    awesome!!! <3
  • gravatar
    #30 Problematic said on the 2011/06/22 at 17:12
    One word: holyfriggincrap!
  • gravatar
    #31 ivan horomanski said on the 2011/06/22 at 17:49
    bien hecho amigos!
  • gravatar
    #32 Ivan said on the 2011/06/22 at 17:50
    Excelent! this is a must have feature of every web application framework. Increases productivity a lot! Also servers as a good reference to standarize! Great Job!
  • gravatar
    #33 andrew said on the 2011/06/22 at 18:18
    That's great! This is really cool.

    But I still miss an admin generator. Will be one?
  • gravatar
    #34 jaimesuez said on the 2011/06/22 at 18:21
    Very exciting obout this! Also I'm worried about admin generator. Some people even are looking solutions out of symfony, because it is not a priority on Symfony2. Look here http://stackoverflow.com/questions/5460011/web-application-admin-generators
  • gravatar
    #35 Nathan said on the 2011/06/22 at 20:38
    Great proof of concept. I'm looking forward to admin generator(s) built similarly; I use the admin generator a lot with Sf 1.

    I personally don't usually like the "wizard" approach, whether command line or web-based, because I always answer something wrong the first time. I like to reuse configuration from other projects/machines, use version control, and search and replace. For all those reasons, I prefer file-based configuration (I love schema.yml and generator.yml). But it looks like that's all still possible so cool.
  • gravatar
    #36 badllama77 said on the 2011/06/22 at 20:43
    Looks fantastic, can't wait to try it out when I get home.
  • gravatar
    #37 Percy said on the 2011/06/22 at 22:28
    ahora las cosas básica que hacen mas rápidas, muy buena iniciativa.

    saludos,
  • gravatar
    #38 Nami said on the 2011/06/22 at 23:39
    I can't call that "awesome", "wonderful" nor "amazing" ... It's far beyond that.
  • gravatar
    #39 Otto said on the 2011/06/23 at 00:01
    Gracias, era lo único por lo que retrasé durante tanto tiempo mis proyectos. Definitivamente era lo único que hechaba de menos de sf1.

    Bien hecho muchachos!
  • gravatar
    #40 Pablo said on the 2011/06/23 at 01:13
    OMG this is GREAT!!!! finally! i was soo tierd of doing this by hand, lol. I hate repetitive tasks.
  • gravatar
    #41 John Bohn said on the 2011/06/23 at 02:42
    Awesome job. The interactivity is great. Any talk of generating unit tests on the getters and setters for entities?
  • gravatar
    #42 Josh said on the 2011/06/23 at 03:40
    I noticed this in the sensio github repository and was excited for what was to come. Good to see what this tool can provide, and looking forward to using it if it suits what I need to do!
  • gravatar
    #43 diasgab said on the 2011/06/23 at 04:20
    Woww!! really great job!! it's a very nice feature
  • gravatar
    #44 Oscar B. said on the 2011/06/23 at 07:06
    Fuuuuu**********k! Awesome! I had an orgasm (yes I did). This is a killing feature, but for sure the lack of it doesn't mean S2 is useless (as someone pointed) Hey! I'm already making $$ with it, and without the generator (yet). I do really love it a lot more than S1. Less magic translates it into less tweaking the generated code, and this doesn't look like magic but a terrible helpfull utility.
  • gravatar
    #45 Pieter S. said on the 2011/06/23 at 08:53
    Nice job!
    1 question, though: how does the gen:doctrine:entity relate to doctrine:generate:entitites?
    Will this command be replaced or is this new command an extra tool to generate yaml files (for instance) that can be used for Entity generation with doctrine:generate:entities?
  • gravatar
    #46 Alin said on the 2011/06/23 at 12:44
    Waited by so many :)

    Can you make all the options configurable instead of interactive?

    There is any command to "generate all"?

    A nice feature will be generator profile, that including generator options and templates (except probably those parts generated by doctrine), specially view templates.
  • gravatar
    #47 Christopher Rasch-Olsen Raa said on the 2011/06/23 at 12:55
    Both Chrome and Firefox give me a black background, but the player seems to think that it is displaying something as it is progressing the ticker. IE displays the video though.

    Anyone else experiencing this?
  • gravatar
    #48 keymaster said on the 2011/06/23 at 15:48
    That is an absolutely fantastic and useful addition. Thank you very much.

    You probably already know this, but you've wet everyone's appetite with anticipation for RC2, in the hopes that perhaps there might be some more surprises.

    (sortable columns, pagination, filtering, ...)

    But even if not, still, thanks very much for all you do for the community.
  • gravatar
    #49 Freddy said on the 2011/06/23 at 19:22
    Hello, any idea how to integrate it into an existing symfony 2 project ? also can it generate complete forms based on entities ?
  • gravatar
    #50 Zuhair Naqvi said on the 2011/06/24 at 05:00
    @Fabien Interactive generation is great BUT can I pre-define generation spec/config for bundles/entities etc. if I dont want to go through generating items one by one? This could mean that down the track a user could generate entire applications out of a generator-spec. Somewhat similar to how Schema.yml is used in SF1.
  • gravatar
    #51 Vlado said on the 2011/06/24 at 11:30
    That's an awesome addition. Symfony's definitely kicking some serious ass!
  • gravatar
    #52 spider said on the 2011/06/24 at 12:04
    Really like the DialogHelper, I was looking for something like it in these days. I'm going to wait for RC1 release.
  • gravatar
    #53 spider said on the 2011/06/24 at 12:09
    Sorry, stupid me: DialogHelper It's already there in the Console related components.
  • gravatar
    #54 Hamza said on the 2011/06/25 at 02:53
    nice!
  • gravatar
    #55 kendoctor said on the 2011/06/25 at 14:26
    yeah. good job. That's the right thing for a new beginner, a lazy man.
  • gravatar
    #56 kendoctor said on the 2011/06/25 at 14:48
    i think , a rapid development tool, need automation features.
    make most practical work more easier just a command line.
    so we can list those most practical work, then make generator to automake .
    1) SCHEMA DEFINITION
    2) HTML + CRUD
    3) JSON + CRUD
    4) USER + AUTHENTICATION + AUTHORIZATION
    5) AJAX CRUD
    6) ADVACNED FORM(NESTED,DYNAMIC FORM FIELDS) BUILDER
    7) .....
    WE NEED MORE PEOPLE WISDOM.
  • gravatar
    #57 xtt1341 said on the 2011/06/26 at 09:24
    very powerful and easy to use , thank you !
    RC1 upgraded , bundle generate OK!
  • gravatar
    #58 bleh said on the 2011/06/26 at 11:33
    You guys should at least test the code on windows before releasing it.

    Tried to follow the video to generate a bundle but twig threw a fatal error during the process.
  • gravatar
    #59 yxl said on the 2011/06/26 at 12:48
    Hi, your demo code generates the Entity with Doctrine generation, @ORM relation and works correctly but in the release there is no @ORM relation and Entity files are being generated differently compared to the screencast which throws exceptions when reading the annotations.

    I believe your local is different than RC1 and those changes did not make it into the RC1, check it out when you have time.
  • gravatar
    #60 Gabriel said on the 2011/06/26 at 15:06
    You guys should at least test the code on windows before releasing it. Tried to follow the video to generate a bundle but twig threw a fatal error during the process. [2]
  • gravatar
    #61 icemaker said on the 2011/06/27 at 10:53
    generate:bundle does not work for me under Windows :/

    I get this error:
    [Twig_Error_Loader]
    Unable to find template "C:/wamp/www/Symfony/src/MyAp/FilmothequeBundle/Controller/DefaultController.php" (looked into: /).
  • gravatar
    #62 Anish Chapagain said on the 2011/06/28 at 17:53
    Namaste and Hello,

    Thanks for such an elegant MVC framework...i really got attached with the developmental works and portfolio included in Website about "Symfony".

    regard's
    Anishchapagain@gmail.com
  • gravatar
    #63 Edgar said on the 2011/06/29 at 18:10
    Amazing work! Tested it on RC3 and works like a charm.

    This saves a LOT of coding and created everything exactly as I would have done it the hard way. I even created the database first when I realized that there's no need to do that, because this will generate everything!

    Note: The validation messages that should appear after we submit the form don't show up on Chrome (latest version) and Firefox (latest version), they only show correctly on Internet Explorer.
  • gravatar
    #64 Diam said on the 2011/07/06 at 01:23
    Hi. Great job but the I am not able to get to URL/post/.
    All files gets created right but I think a configuration on routing.yml or config.yml may be missing on Symfony2 RC4. Does someone gets the same error?
  • gravatar
    #65 Diam said on the 2011/07/06 at 01:25
    I get a:
    No route found for "GET /post/"
  • gravatar
    #66 Diam said on the 2011/07/06 at 15:05
    So i believe the error is due to a windows incompatibility. Console error is:

    Importing the bundle routing resource: FAILED


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


    Bundle UdmFutBundle is already imported.
  • gravatar
    #67 Oleg said on the 2011/07/09 at 02:48
    I did all as in this video, from clear installing symfony2.
    In the end I got "No route found for "GET /post/"
    Using windows and Symfony2 Standard RC2
    I'm checked router list by using "router:debug" command but nothings about "Post" action in routing list.

    Check my screenshot.
  • gravatar
    #68 Oleg said on the 2011/07/09 at 02:50
    I did all as in this video, from clear installing symfony2.
    In the end I got "No route found for "GET /post/"
    I using windows and Symfony2 Standard RC2
    I'm checked router list by using "router:debug" command but nothing about "Post" action in routing list.

    Check my screenshot
    http://www.freeimagehosting.net/uploads/8ad5fe380f.jpg
  • gravatar
    #69 Oleg said on the 2011/07/09 at 02:53
    Oh My Mistake, I using Symfony 2 Standart RC4 :) but not RC2
  • gravatar
    #70 Oleg said on the 2011/07/12 at 22:45
    Anybody know what the problem with router in RC4 after generated crud?
  • gravatar
    #71 aesthetics data said on the 2011/07/13 at 21:25
    I've just installed symfony 2 RC4 with vendors. And when i click on "go to welcome page" i've got the error : NotFoundHttpException: No route found for "GET hp/" . It's a fresh install and already broken...
  • gravatar
    #72 Oswald said on the 2011/07/21 at 19:27
    Hi!

    Does anybody have find a solution for that matter : "The command was not able to configure your everything automatically.
    You must do the following changes manually. " ?

    I use the RC4.

    Thanks a lot.

    byby