In the short attention span of most fellow PHP developer’s, here the first 5 great reasons to use Symfony. (Update: part 2 is here.) This is by no means a full explanation of Symfony, but just enough to get you running over to the documentation to learn more.
Few general highlights first:
- Enterprise Ready – (used for Yahoo bookmarks)
- Many Plugins available (eg. authentication, authorization, client side validation, thumbnail, rss)
- Actively developed
- Good documentation
1 – Ajax and Javascript
With all the hype surrounding web II.0, any major PHP framework has to add some Javascript and Ajax support. Symfony gives you a few nice building blocks. Small example:
<?php echo form_remote_tag(array(
'url' => 'project/addReply',
'update' => 'replys',
'complete' => visual_effect('highlight', 'replys').
"Element.hide('addReply')",
'position' => 'bottom',
), 'id=addReply style=display:none;') ?>
<?php echo input_hidden_tag('id', $project->getId()) ?>
<?php echo textarea_tag('body') ?><br />
<?php echo submit_tag('submit') ?>
</form>
<?php echo link_to_function('Add a reply', visual_effect('toggle_appear', 'addReply')) ?>
This little snippit gives you an AJAX form, which submits its data to project/addReply (module/action). With a nice visual effect for appearance. Extremely fast to implement and extend. Have a look at my ajax comment form example.
Read More: Ajax in Symfony
2 – Instant admin interface: Advanced crud generation for admin interface
Useful for almost any type of website. Say you have a job listing website, run the command:
symfony propel-init-admin backend listing listings
and there you have your crud admin interface ready. Pretty, friendly, fully featured and without writing a single line of code.
But wait, what if I want to include feature X in the admin interface? Symfony uses a generator.yml configuration file which allows you to set filters and customize your admin interface. Most of the time this will more than fulfill your needs and you will easily create complete and functional backends.
See it happening: Generator Movie
3 – Nice Urls: The Routing System
Symfony uses a frontend controller, in which all requests are managed through a single frontend. This makes creating nice urls simpler than ever.
post:
url: /weblog/:title
param: { module: post, action: permalink }
list_of_posts:
url: /latest_posts
param: { module: post, action: list }
How does that compare to writing htaccess files?
If you for instance would want the url for member profiles on your site to be www.mysite.com/members/member-name you would simply use:
url: /members/:membername
param: { module: users, action: show }
The url indicates how you want the url to look and the param value tells Symfony where the code is located.
Read More: Links and the routing system
4 – Form Handling: Fillin, Validation and Creation
One of the areas where Symfony really shines is the handling of forms. The code for generating forms is clean and easy to understand and learn.
<?php echo select_tag('name', options_for_select(array(
'Steve' => 'Steve',
'Bob' => 'Bob',
'Albert' => 'Albert',
'Ian' => 'Ian',
'Buck' => 'Buck'
), 'Ian')) ?>
=> <select name="name" id="name">
<option value="Steve">Steve</option>
<option value="Bob">Bob</option>
<option value="Albert">Albert</option>
<option value="Ian" selected="selected">Ian</option>
<option value="Buck">Buck</option>
</select>
Furthermore validation and re-filling the form is done in a configuration file. This keeps your code and templates nice and clean. An example:fillin:
enabled: true
fields:
name:
required:
msg: The name field cannot be left blank
sfStringValidator:
min: 2
min_error: This name is too short (2 characters minimum)
max: 100
max_error: This name is too long. (100 characters maximum)
With some simple config lines you can take care of fillin and validation. For the skeptics, off course you can define your own validators. As far as I’ve experienced you can pretty much extend Symfony any way you like, with minimal effort. If you want client side validation as well you can opt to do so by installing one of the many plugins.
Read More: Forms in Symfony
5 – Debugging on Steroids
We all wish our code to run smoothly in the first try. However the only way to achieve this is to never try anything new. If we have to Debug, let it at least be fast. Symfony provides us with a few awesome tools. First one is the developer toolbar.
Showing you: 1. your application variables (useful for multiple development environments) 2. logs and messages (all the steps used for executing the page, perfect for debugging) 3. the number of queries and their sql 4. the size of the page 5. the load time throughout various points of the code.
If you do something wrong related to Symfony, it gives you a nice explanation of the problem, through it’s custom error display. Installing the famous Xdebug extension further increases the amount of information displayed.
Read More: Application Management Tools
All these little things together make developing with Symfony a joy. More goodness to come up in part two of this post.
(Watch out with installing Symfony though. It will take you anywhere between 30 seconds and two days. Depending on your experience with PEAR. There are some great install guides on the Symfony Wiki.)
Update:
Part 2 has been published: Ten Reasons why Symfony rocks – part 2










ruzz on symfony | Blog Archive » here here responded on 18 Aug 2007 at 9:51 pm #
[...] we need more talk like this. Ten reasons why Symfony rocks – Part 1 [...]
Nathaniel B responded on 18 Aug 2007 at 10:25 pm #
Great write-up, I’m looking foward to your second part that highlight’s symfony’s abilities!
Cheers :)
10 Gründe warum Symfony rockt - Ablage - blogged on responded on 19 Aug 2007 at 4:42 pm #
[...] Ten Reasons why Symfony Rocks bei Mellow Morning 19.08.2007 um 18:13 in Ablage von dave · RSS 2.0 feed. Schreibe ein Kommentar oder setze einen Trackback auf deine Seite. [...]
t8d blog » Blog Archiv » 10 Gründe, warum Symfony rockt responded on 20 Aug 2007 at 7:29 am #
[...] Schellenbach zeigt 10 gute Gründe, warum man sich das PHP Framework Symfony mal genauer ansehen [...]
rpsblog.com » A week of symfony #33 (13->19 August 2007) responded on 20 Aug 2007 at 9:34 pm #
[...] Ten reasons why Symfony rocks – Part 1 Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages. [...]
gillbates responded on 21 Aug 2007 at 7:44 am #
thanks for writing this. good writeup from someone who has spent time learning the framework
James responded on 23 Aug 2007 at 6:39 am #
Geweldig artikel, wanneer kunnen we deel 2 lezen ?
Ik ben benieuwd naar de overige mogelijkheden van dit framework.
Mellow Morning » Ten reasons why Symfony rocks - Part 2 responded on 08 Sep 2007 at 8:00 pm #
[...] you weren’t convinced by the first 5 reasons why Symfony rocks, you will certainly be [...]
Blog responded on 11 Sep 2007 at 10:16 pm #
Warum symfony rockt…
Für den Fall das einige Leute immer noch nicht begriffen haben warum symfony so rockt, hat Thierry Schellenbach die 10, seiner Meinung nach, wichtigsten Gründe aufgezählt. Und ich kann nur dazu sagen, der ja so Recht Ten reasons why Symfony rocks …
Mellow Morning » Quick Symfony trick - The remote_function workaround responded on 30 Sep 2007 at 12:15 pm #
[...] mentioned in previous posts, Ajax in Symfony is a very easy experience. However sometimes the pre-made functions don’t provide all the functionality you [...]
tschellenbach responded on 08 Oct 2007 at 7:44 pm #
Hi Thierry,
I was just reading your blog article about symfony handling AJAX forms (http://www.mellowmorning.com/2007/08/18/ten-reasons-why-symfony-rocks-part-1/)
Since I’m developing a small application with Symfony at the moment, I was trying to set up something similar like you did with your demo-guestbook (http://www.mellowmorning.com/symfony-examples/comment). Unfortunately, it didn’t work yet…
My question: Could you send me the action, that is handling the request being sent by the AJAX form? I think that could help me a lot with understanding how this works.
Thanks in advance and regards from Germany,
Matthias
tschellenbach responded on 08 Oct 2007 at 7:45 pm #
Hey Matthias,
Glad to see you are exploring Symfony.
I added some comments to the action to clarify.
Hope it helps :)
Note that there is some additional code in there, for added functionality from:
http://www.mellowmorning.com/2007/09/08/ten-reasons-why-symfony-rocks-part-2/
public function executeUpdate(){
//if not an ajax request send them a 404
if(!$this->getRequest()->isXmlHttpRequest()) $this->forward404();
$comment = new Comment;
$comment->setAuthor($this->getRequestParameter('author'));
$comment->setBody($this->getRequestParameter('body'));
$comment->save();
//set the comment variable for the template
$comments[] = $comment;
$this->comments = $comments;
//dealing with caching
$sf_root_cache_dir = sfConfig::get('sf_root_cache_dir');
$cache_dir = $sf_root_cache_dir.'/frontend/*/template/*/all';
sfToolkit::clearGlob($cache_dir.'/*/*/comment.cache');
sfToolkit::clearGlob($cache_dir.'/*/comment.cache');
}
Cheers,
Thierry
Simon responded on 12 Oct 2007 at 10:12 am #
Symfony’s certainly got some awesome points, I’m developing something using it at the moment for about 4 weeks now.
First off, I agree completely with the points above, but for those purists.. I have a few nags:
I am pretty annoyed about standards however. The form validation puts stray div’s with custom style=”display:none” If there has not been an error, which makes your code look ugly.
The Ajax helpers use “document.write” INLINE for writing Ajax updaters etc.. now thats just nasty – I really like my prototype to be nicely bundled, and chucked into a included file, with some nice prototype.behavior extensions to apply them to my elements (seamlessly).
It’ll be interesting to see I can get around the inbuilt form validation, and implement my own version too, thats what I’m battling with at the moment.
tschellenbach responded on 12 Oct 2007 at 10:20 am #
So far I really like Symfony’s architecture, it is all very extensible. Quite complicated, but very extensible.
Most of the time (so far for me, always) you can change the frameworks behavior, without any danger of creating future compatibility with updates.
links for 2007-10-16 | xanders blog responded on 16 Oct 2007 at 5:27 am #
[...] Mellow Morning » Ten reasons why Symfony rocks – Part 1 (tags: symfony php validation tts ajax web2.0) « links for 2007-10-12 [...]
What’s cooking at Tech-Recipes » Blog Archive » Happy birthday symfony responded on 20 Oct 2007 at 3:00 am #
[...] search was quickly and richly rewarded. I found lots of glowing references for the symfony framework. Symfony is so much more than what I was looking for, but [...]
Mellow Morning » Introducing a cross site ajax plugin for Prototype responded on 25 Oct 2007 at 9:00 pm #
[...] doing Ajax was my main reason to choose the prototype framework. Furthermore it is also included in the great Symfony framework. In Prototype Ajax requests are written like [...]
Mellow Morning » A new job! - but no Symfony responded on 20 Jan 2008 at 10:43 pm #
[...] done an absolutely amazing job. My opinion on the framework is best described by these blog posts Part1, Part2. However the current project we are working on has some special requirements. First of all [...]
Lawrence Krubner responded on 16 Jul 2008 at 9:34 pm #
Your link is broken:
“Update: part 2 is here.”
I clicked on that, at the top of your post, and it took me no where.
tschellenbach responded on 17 Jul 2008 at 8:20 am #
Fixed
Mellow Morning » Django vs Symfony responded on 27 Aug 2008 at 7:52 pm #
[...] you can see from the posts (one, two) I’ve always been a large Symfony fan. Symfony is really great, but my current favourite [...]
Daily Digest for 2008-08-28 | Pedro Trindade responded on 29 Aug 2008 at 7:55 am #
[...] Mellow Morning » Ten reasons why Symfony rocks – Part 1 [...]