Symfony Timesaver Tip: One minute to initialize and map your bundle’s entity classes to your existing database tables

If you’ve designed your database and set it up, there’s a quick way to initialize your Symfony bundle to start talking to it within a minute! Here is where using a framework to do those mundane coding tasks empowers developers to focus their time and energy creating solutions and less time focusing on creating tools and setting up an environment to create those solutions.  After all, a lot of those tools are used in one form or another for many different projects, aren’t they?

As a developer, imagine if you have to keep writing some version of PHPMyAdmin over and over again, knowing that PHPMyAdmin does a better job.  That’s where using a PHP framework starts to really put muscle in any company’s web development team.  GET THEM ON A FRAMEWORK!  You’ll be happy you did later.

If you don’t have a YML file but have a table on your database, run this command to import YML file from your database. You can filter by a single table name, but be sure to use the camelCase names since this references Symfony’s objects, which are called Entities. This actually makes sense since as a coder you need to easily distinguish your database field names which usually incorporate underscores, from the class properties that also use class methods which use camelCase.

php app/console doctrine:mapping:import YourAppBundle yml –filter="Table"

Based on an YML File this command will create a single entity for you:

php app/console doctrine:generate:entities YourAppBundle:Table –path src/

And if you want to create all entities

php app/console doctrine:mapping:import YourAppBundle yml
php app/console doctrine:generate:entities YourAppBundle

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *