19
Some helping hands when working with embedded doctrine relations in symfony forms
9 Comments · Posted by Christian in The right tool
Many of you will have been confronted with the symfony form sub-framework at some point. And when you had to work with model relations that were a tad more complicated that the examples from the documentation you will have experiences difficulties. I know I have. There are however three interesting plugins that can be of great help.
Let me start with the most simple one of them.
sfAdminHijackPlugin
(http://github.com/caefer/sfAdminHijackPlugin)
This is one my own plugins and provides a single and very simple functionality for one-to-many relations. It provides a widget that you can use on the column that contains the foreign key.
You will then get a JQuery powered widget that lets you choose from existing objects to be related using autocomplete search. You can delete a relation and you can add one on the fly with a JQuery modal dialogue.
See my older post for more detailed information.
ahDoctrineEasyEmbeddedRelationsPlugin
(http://www.symfony-project.org/plugins/ahDoctrineEasyEmbeddedRelationsPlugin)
This plugin provides much more functionality that the first plugin. To use it your forms have to inherit from a form class included in the plugin. It overloads the embedRelation() method which you can use to add, change and delete relations.
It will change your form markup to include a UI for all these interactions. This plugin is highly configurable which unfortunately can result in misconfiguration and spending a few moments to figure out the correct options for your requirement.
Once set up though it will work like a charm.
Update: this is no longer recommended. See comments for details!
sfDoctrineDynamicFormRelationsPlugin
(http://github.com/kriswallsmith/sfDoctrineDynamicFormRelationsPlugin)
The last plugin is my personal favourite as it does not force you to change your inheritance chain or to accept form markup. It only takes care about the backend for handling adding, changing and deleting relations from the form data send in a request. The rest is fully up to you. You can use your favourite Javascript library or homegrown functionality to make dynamic changes to the form markup and the plugin will take care of handling the additional data.
This plugin provides a new method embedDynamicRelation() which takes care of the backend part of the form only. You can use Javascript to handle the frontend (extending, reducing the form). This is what I use in the page composition feature.
See also Kris Wallsmith’ talk on symfony day 2010 (slides 86-103) for more info.
I hope this saves somebody a few headaches.
Doctrine · forms · plugins · symfony
<< How to create a custom admin theme for the symfony/doctrine admin generator


Pingback: Tweets that mention • Some helping hands when working with embedded doctrine relations in symfony forms | test.ical.ly -- Topsy.com