Last Updated: January 28, 2019
· zoltanradics

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.

2 Responses
Add your response


thanks, going to need this :D

over 1 year ago ·

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 ·