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


  Archive for July, 2007

July 29, 2007 – 5:30pm svn add new files, remove all svn directories

to add all new files in a project to the respository you can use either:

svn status | grep "^\?" | awk '{print $2}' | xargs svn add
svn status | grep "^\?" | sed -e 's/? *//' | sed -e 's/ /\\ /g' | xargs svn add

to remove all svn directories from a project:

find . -iname '.svn' -print0 | xargs -0 rm -rf

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 23, 2007 – 8:45pm Prototype Tabs Script released, Scriptaculous Optional

We just released a small script that allows you to easily create tabbed content on your web sites with a nice fade effect. Having searched for a decent script that uses prototype.js and scriptaculous to quickly create tabbed inline content and not having found one, we were inspired to create our own, much as stickmanlabs did with the accordion script. Check out the prototype tabs demo.

Posted by in  Web Development   |     |  5 Comments »

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 »

July 19, 2007 – 2:36am Javascript Array Merge: array_merge

Using protoype.js I discovered a quick way to merge to arrays in javascript:

function array_merge(one, two) {
  return one.flatten();

This definitely beats the alternative of iterating through the second array by hand and adding it to the first. Any comments or suggestions are welcome.

Posted by in  Web Development   |     |  9 Comments »

July 16, 2007 – 11:57am Symfony init-batch

Before version 1.0 I was writing my batch scripts by hand, usually cutting and pasting from other batch scripts. At some point the


command became available. This is how it works:

symfony init-batch default [yourBatchName] [yourApplicationName]

This creates a new file in your project/batch directory with the following content:

 * yourBatchName batch script
 * Here goes a brief description of the purpose of the batch script
 * @package    yourProject
 * @subpackage batch
 * @version    $Id$
define('SF_ROOT_DIR',    realpath(dirname(__file__).'/..'));
define('SF_APP',         'yourApplicationName');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG',       1);
// initialize database manager
//$databaseManager = new sfDatabaseManager();
// batch process here

Nice! Credit goes to those who posted in the forum for details about this great command line tool.

Posted by in  Uncategorized   |     |  2 Comments »