Symfony Links: Symfony2 Service Config Converter & Create your own framework & Symfony2cheatsheet

Symfony2 Service Config Converter

I just found on twitter  a nice Symfony service config converter: http://converter.rosstuck.com/

Also usable as a symfony command.
https://github.com/rosstuck/TuckConverterBundle

I think this is great to convert examples into your desired format.

And a simple link is pretty boring! So there are two more links…

Create your own framework… on top of the Symfony2 Components

http://fabien.potencier.org/article/50/create-your-own-framework-on-top-of-the-symfony2-components-part-1

A very nice tutorial from Fabien Potencier. And it is also a good start to get an overview over some symfony components.

Symfony2cheatsheet

An – for me – older link is the cheatsheet:
http://www.symfony2cheatsheet.com/

Just noticed that I did not used it so far… damn you… google search box!

From MySQL-Workbench to Sonata-Admin

Goal:

Design your Database inside MySQL-Workbench and get a nearly completely auto generated Sonata Admin from your MySQL-Workbench schemata.

Preface:

Working as a web-developer I was mostly confronted to create a unique and custom data model for the customer. I started to use MySQL-Workbench to design my data structure and followed on that I looked for a way to get my created structure directly into PHP models and an auto generated database.

Years ago for the bmw motorcyle community (Zend Framework) I started with a simple macro to just create to create the database structure. After that I used Doctrine to generate my models. So I used it only as a project start.

With an auction platform for the “Österreichische Bundesforste AG” (Agavi) I found a nice schema exporter for the MySQL-Workbench. After some testing I could make some steps further. With the yaml export and the doctrine “generate-migrations-diff” I could also auto generate migrations after changing my data model inside MySQL-Workbench.

Now with Symfony I am still using the schema exporter from johmue. I created a fork to fit my needs for my Symfony projects and it fits perfectly to get an easy and quick way from the MySQL-Workbench to a Sonata-Admin. And I created a Bundle the integrate the exporter into Symfony.

Prerequisites:

Steps:

Install Symfony:

http://symfony.com/doc/current/book/installation.html

Install the MySQLWorkbench-Exporter and the Exporter-Bundle:

Configure Exporter Bundle:

See https://github.com/HydraxSkarrag/mwbs-exporter-symfony-bundle#configuration

schema_name here refers to name of the Workbench file without the extension (mwb). Workbench files are saved in the Resources/workbench/ directory as *.mwb inside your bundle.

 Create your schema with MySQL-Workbench:

I think the MySQL Workbench is pretty much self explaining. Create your tables and relations and than save your file to your Bundle /Ressources/workbench/schema_name.mwb

Export your schema and create your database tables:

Export the schema:

Check the changes to your database:

Update your database:

Install Sonata Admin:

See the offical dokumentation: http://sonata-project.org/bundles/admin/master/doc/reference/installation.html

I am using the SonataDoctrineORMAdminBundle.

Follow to Step 2.1 http://sonata-project.org/bundles/admin/master/doc/reference/getting_started.html and stop after this step (2.1). You can use the sonata generator for the following steps.

Create Admin classes with the generator:

I suggest to create an extra bundle for you admin generator.
e.g. YourProjectAdminBundle.

To create the admin classes you can use this command:

Run your Sonata Admin and get lucky:

Browse to your site with /admin.

As you can see, the admin generator does not auto include your references. You have to add in on your own. And the ID for the edit mask should be removed.

How to change your Sonata Admin?

  1. Make your changes inside the MySQL-Workbench
  2. Export your entities
  3. Update your database
  4. Recreate your Sonata Admin or manually add your new fields (or remove.. or whatever)
  5. get lucky (again)

Questions? Errors?

Please use the comments!

Symfony2 on MAC using MacPorts

There are several good articles on installing MacPorts.

You can simply follow the instructions in the articles above. To get the basic extensions for symfony you can use one of the following port installs. Depending on the PHP version you want to use. I like the side by side version.

standard PHP:

side by side: