SUBSCRIBE VIA RSS


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.

Topics

Stack Overflow


The old fashioned way

RECENT TUNES

  Symfony Articles

December 10, 2008 – 8:05pm Starting a new symfony project: Tips for sanity and bliss with SVN

There is something gratifying about starting a new project. You get to start fresh and it may be the only time during the project lifespan where everything is perfect.

Over time I’ve learned a few tricks that personally make my project environment a pleasure to work with. More…

Posted by in  Web Development   |     |  9 Comments »

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!

January 24, 2008 – 4:37pm Installing Symfony on Leopard

I’ve found the best way to install symfony on Leopard is to use the version from SVN. I find this is easy to do, and easy to update in the future. Here is a cheat sheet for those looking to get up and running with symfony on their Mac running 10.5 Leopard. More…

Posted by in  OS X Web Development   |     |  4 Comments »

January 14, 2008 – 2:55pm symfony propel-load-data

Loading data from fixtures can be extremely useful to pre-populate your database so you have something to test and code with. I frequently use the propel-load-data task in two ways, the first when altering the schema, and the second to add some new data on top of whats in the database.

This will rebuild your db and model from schema.yml, insert the new structure into your db, and load data from the fixtures in /data/fixtures:

./symfony propel-build-all-load frontend

To load in additional data from a specific fixture file, you can use this command:

./symfony propel-load-data frontend dev data/fixtures/[filename].yml append
Posted by in  Web Development   |     |  3 Comments »

December 13, 2007 – 12:54am Propel Set Distinct: setDistinct()

Propel’s use of the Criteria class has many unknown features documented deep within the propel API. One of my favorites is setDistinct(), which will add the DISTINCT keyword into the start of your query. This is very useful when you want to create a select menu that presents a list of pre-existing values for a column in your database. More…

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:

sfConfig::get('sf_upload_dir_name')

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:

sfConfig::get('sf_upload_dir')

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:

all:
  dir:
    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):

sfConfig::add(array(
  '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 »