Pages

Tuesday, May 28, 2013

Creating forms in Symfony2 Part I

Symfony2 command line tool has provided a excellent way to create forms without too much bother about the code.
 
  Now i am going to create all forms(CRUD) for "blog_user_level" table. Guess how much time will I spend for it. OK  keep that in your mind.

First of all i create entity for the "blog_user_level" to do that run fallowing command in the terminal.

     $ php app/console generate:doctrine:entity

then it will ask fallowing parameters.

    The Entity shortcut name: AcmeUserBundle:BlogUserLevel
    Configuration format (yml, xml, php, or annotation) [annotation]: xml
    New field name (press <return> to stop adding fields): name
    Field type [string]:
    Field length [255]:

    New field name (press <return> to stop adding fields): level
    Field type [string]: integer

    New field name (press <return> to stop adding fields):

    Do you want to generate an empty repository class [no]?


    Do you confirm generation [yes]? 


then update the database
    $ php app/console doctrine:schema:update --force
now we want to create crud. to do that
    $ php app/console generate:doctrine:crud --overwrite

then it will ask some parameters

    The Entity shortcut name: AcmeUserBundle:BlogUserLevel
    Do you want to generate the "write" actions [no]? yes
    Configuration format (yml, xml, php, or annotation) [annotation]: xml
    Routes prefix [/bloguserlevel]:

    ...........


  
Sometimes it will ask to update routing.yml file. yeh that's all.
now go to the http://localhost:8000/bloguserlevel/ and test CRUD application.







No comments:

Post a Comment