Subscribe to our feed

Symfony Experts

Symfony Experts
If you have an urgent question for a symfony-related issue, this is the place to ask.


Stack Overflow

The old fashioned way


  PHP Articles

January 23, 2009 – 4:42pm Uploading a file with Symfony 1.2

There is a post hidden within the symfony documentation that discusses how to upload a file using the new forms framework within symfony 1.2. If you are curious about the best way to handle file uploads, it’s worth reading this What’s New in Symfony 1.2 post first, and then come back here for a quick summary of how this works.

Let’s say you would like to allow users to upload PDF files to your site. You store data related to these file uploads in an “article” table in your database. This table has a column named “file” that stores the file name of the uploaded pdf.

The symfony forms framework will generate the basic (and not so basic) code to get you started. If you haven’t yet generated your form classes yet, you can do so with the command:


November 21, 2008 – 1:08pm Installing Xdebug for PHP on OS X Leopard with Entropy PHP 5

I was so ready to get my hands dirty with this. Like most cases where I try to install a custom extension or php library, the directions may appear easy but it never quite goes so smoothly. More…

Posted by in  Uncategorized   |     |  Comments Off on Installing Xdebug for PHP on OS X Leopard with Entropy PHP 5

February 29, 2008 – 1:45pm Propel Transactions with Symfony

It’s easy to create transactions with Propel. This can be very useful when you are deleting rows from your database from multiple tables, and want to do an “all or nothing” approach so that things don’t get messy. More…

January 24, 2008 – 4:48pm Propel Criteria Left Join: using addJoin() and addAlias() to join a table twice

Here is a way to do left join on two columns in a table that both were foreign keys in the same table using Propel. This might happen if for example you have a table with a parent_id and a child_id in a nested set that both refer to the same table, or as an example you have a table “documentation” and each documentation can be categorized into a main category and a sub category.

What happens when you want to do a left join in your documentation query, so that if present both the related category and sub_category objects get included in the results?

$c->addJoin(DocumentationPeer::CATEGORY, CategoryPeer::ID, Criteria::LEFT_JOIN);
$c->addJoin(DocumentationPeer::SUB_CATEGORY, CategoryPeer::alias('c2', CategoryPeer::ID), Criteria::LEFT_JOIN);
$c->addAlias('c2', CategoryPeer::TABLE_NAME);

Done and done!

November 16, 2007 – 4:57pm Sending Email within Symfony

Symfony allows you to dish off the responsibility of sending an email to another module/action when necessary, which can be great because it can utilize the “view” aspect of the framework so you can store your email formatting (plain text or HTML) as a template just like you would for a regular action.

As I don’t use this functionality that often, I usually forget how to pass parameters over to this other mail action, such as the id of the object I am working with or the recipient’s email address.

Sending Email with a Custom Action
In this example we’ll be sending an lease application notice to the manager of a property. After the application is saved, we want to send an email to the property manager containing the property name and applicant name, and include a link for them to login and view the complete application.

In our “save” action of the “leaseApp” module, right after the application is saved we’ll send off the email, and we can do this (as outlined in the symfony cookbook) by delegating to another action. More…

Posted by in  Web Development   |     |  7 Comments »

August 16, 2007 – 5:09pm New symfony plugin: sfLightWindowPlugin

We’re pleased to announce the release of our latest symfony plugin, sfLightWindowPlugin. sfLightWindowPlugin provides great helper functions for LightWindow v2.0. LightWindow is a great improvement over the original Lightbox 2 script, and includes handlers for virtually all media types, including flash, quicktime, youtube videos, images, remote content, inline content, and more. Using this plugin, it’s amazingly simple to add these great effects to your symfony site.

Check out the sfLightWindowPlugin Demo for a closer look. You won’t be disappointed!

To download the sfLightWindowPlugin, visit the wiki page for download and installation instructions.

Posted by in  Web Development   |     |  23 Comments »

July 26, 2007 – 11:31am sfCombineFilterPlugin released: Combine js and css requests into single compressed files

The sfCombineFilter plugin automatically combines included js and css files in your web response into one request each, passing the string of file names to a special php file that concatenates them and compresses them for faster delivery. This file is then cached for future use.

Information and download instructions are available in our code section: sfCombineFilter

July 20, 2007 – 6:14pm Symfony: path to upload directory, other sf_* config values

sf_upload_dir, sf_upload_dir_name, sf_data_dir… I know there are a lot of configuration values available throughout the symfony code, but I don’t use them enough to remember what they are exactly. The Symfony Upload File documention helps describe which paths you need for for file uploads. In your templates/view, you will want to use:


This will usually be the string “uploads” unless you changed the setting in your configuation. When you need the *full path* to the file on your web server, say to move or save the uploaded file, then you use:


To make things easier, usually I will use those configuration settings in conjunction with a custom setting for the type of media I am uploading. Say for example I have a “Person” table that has a column named “photo”. This column stores a file name of a person’s picture. I want to store all of these photos in web/uploads/photos. First, I’ll add a setting to my app.yml file:

    photo:    "photos"
    doc:       "docs"
    logo:      "logos"

Then in my lib/model/Person.php, I’ll add a method to give me the web path:

public function getPhotoPath()
  return $this->getPhoto() ? '/' . sfConfig::get('sf_upload_dir_name') . '/' . sfConfig::get('app_dir_photo') . '/' . $this->getPhoto() : null;

May seem like a lot of code, but now anytime I want to display the person’s picture in a template I can use:

<?php image_tag($person->getPhotoPath()) ?>

If I ever decide to move all the stored photos into another directory, perhaps because it’s growing too large and we want them in subfolders based on username or something, then all we have to do is change it in one place and we can be certain no existing templates will break.

If instead you wanted to change the actual ‘uploads’ path, then you can override the symfony parameter in your project’s config/config.php file (note this is copied from the symfony documentation page linked to above):

  'sf_upload_dir_name'  => $sf_upload_dir_name = 'uploads',
  'sf_upload_dir'       => sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.sfConfig::get('sf_web_dir_name').DIRECTORY_SEPARATOR.$sf_upload_dir_name,      

As a final note for the curious, if you look in your symfony directory (the actual symfony code base, not your project directory), you can take a look at all of the sfConfig values in config/constants.php. Here are a few variables and their default values that might come in handy:

$sf_root_dir    = sfConfig::get('sf_root_dir');
$sf_app         = sfConfig::get('sf_app');
$sf_environment = sfConfig::get('sf_environment');
$sf_bin_dir_name     = 'batch',
$sf_cache_dir_name   = 'cache',
$sf_log_dir_name     = 'log',
$sf_lib_dir_name     = 'lib',
$sf_web_dir_name     = 'web',
$sf_upload_dir_name  = 'uploads',
$sf_data_dir_name    = 'data',
$sf_config_dir_name  = 'config',
$sf_apps_dir_name    = 'apps',
$sf_test_dir_name    = 'test',
$sf_doc_dir_name     = 'doc',
$sf_plugins_dir_name = 'plugins',
Posted by in  Web Development   |     |  2 Comments »

June 18, 2007 – 12:15pm Linking between Apps within Symfony

There has been some recent discussion on the symfony mailing list about cross-linking between apps within the same project. I have managed to avoid having to use complex routing rules and instead have gotten away with adding absolute URLS to my app’s settings.yml file, and then using these addresses within my templates.

First, add appropriate URLs in the project’s config/app.yml file. As there are different settings used depending on the environment, you can put the full URL here and have it automatically use the right setting.

   frontend:  http://myappdev/frontend.php
   backend:  http://myappdev/backend.php

Then, in your template, whenever you need to link to the other app, use these settings:

<?php echo link_to('Admin Site', sfConfig::get('app_url_backend')) ?>
<?php echo link_to('Public Site', sfConfig::get('app_url_frontend')) ?>
Posted by in  Web Development   |     |  4 Comments »

June 17, 2007 – 10:21pm Symfony Resources

Even after working with Symfony for over a year, we still have to refer back to various resources to help us along the way. This is a list of useful resources for a symfony developer, including links to the sometimes hard to find Creole API, Propel API, and Propel docs.

Posted by in  Web Development   |     |  Comments Off on Symfony Resources