2io2nw
Last Updated: February 25, 2016
·
5.055K
· zoltanradics
360

Symfony2: Generate code based on your database

The first step is create your database structure. Once you are ready you can easily generate your code via Symfony CLI tool.

1. Generate the ORM files:

$ php app/console doctrine:mapping:convert yml ./src/ExampleVendor/SomeBundle/Resources/config/doctrine/metadata/orm --from-database --force

In this example we use YML mapping type. You can choose also XML or PHP if you more familiar with them.

2. Generate the annotation files:

$ php app/console doctrine:mapping:import ExampleVendorSomeBundle annotation

3. Generate the entity files:

All of them:

$ php app/console doctrine:generate:entities ExampleVendorSomeBundle

Some of them:

$ php app/console doctrine:generate:entities ExampleVendorSomeBundle:AnyEntity

4. Generate the whole package:

$ php app/console generate:doctrine:crud

This will generate your controller files, formtype files and all views.

Say Thanks
Respond

2 Responses
Add your response

14822
Me

thanks, going to need this :D

over 1 year ago ·
14823
360

Welcome! If any topic come into your mind about Silex or Symfony, just drop me a sign and i will see if i can do a pro tip about that. (i have ran out of ideas)

over 1 year ago ·
Filed Under