Symfony Eclipse integration plugin

I wrote simple symfony plugin that integrates symfony tasks into Eclipse/PDT.

Plugin features:

  • Run core tasks, plugin tasks and your custom tasks.
  • Ask interactively for required tasks parameters.
  • Tasks list is always up-to-date, it is updated each time you run clear:cache.

Basically this plugin just creates proper xml build-file for Ant Eclipse plugin. Here how it looks like:


Sunday, October 24th, 2010

Running remote tasks with symfony

I was tired of logging to production servers and clearing cache each time after deploy. So I wrote this simple plugin which allows to run any remote tasks right from your dev environment. All you need now is to type something like:

./symfony project:remote production cc

To install plugin:

  1. download attached package oxtRemoteTaskPlugin-1.0.0.tgz
  2. install it
    ./symfony plugin:install oxtRemoteTaskPlugin-1.0.0.tgz
  3. clear the cache
    ./symfony cc

Configure remote host if you haven’t done that yet:


Now you are ready to run remote tasks.
If remote task consists of more than one word, enclose it in quotes, just like you do for any command line argument:

symfony project:remote production 'cc --app=frontend'

This plugin is basically a wrapper for ‘ssh’ command. It won’t work on vanilla Windows.

Monday, October 18th, 2010

Symfony Doctrine Sluggable – rebuilding empty slugs

If you add slugs with Sluggable behaviour in the middle of your project you’ll have empty slugs for all old records. To fix it you need to save your models via symfony, slugs will be built automatically.

You can automate it with help of this simple task:

Wednesday, August 25th, 2010

Symfony, propel and long running scripts

For long running scripts in symfony with propel ORM you may experience problems with memory usage. To avoid them make sure to disable propel instance caching by calling this code at the beginning of the script:


Propel by default caches in memory all fetched database objects. That means that for scripts with extensive db usage or long running time you may hit php memory_limit sooner or later.
Starting with propel 1.3 shipped with symfony 1.3 and 1.4 which are about to be released you’ll be able to disable instance pooling in database yaml config.

Saturday, November 28th, 2009

symfony: sfValidatorFile – invalid mime type (text/plain) for PNG images

On some systems sfValidatorFile may give you an error when trying to upoad PNG images. It says that it has invalid mime type – text/plain, though you have 'mime_types' = 'web_images' and other image formats work well.

It may be caused by wrong result from mime_content_type() function. To check if it’s your case create simple php script with just one line:

echo mime_content_type('path_to_your_png_image');

If it will give you text/plain then you have three options:

  1. Upgrade your PHP to 5.3.0, though I doubt it’s available for most *nix distributions at this time.
  2. Install PECL package Fileinfo.
  3. The easiest, modify form class.

In first two options sfValidatorFile will use finfo_open function prior to mime_content_type and it should give correct results for PNG image. However, upgrading PHP or installing PECL package isn’t always possible.

The simplest way to fix this bug is to apply small modifications to your form class, just reorder mime type guessers:

public function configure()
  $this->validatorSchema['image'] = new sfValidatorFile(array(
      'required'	=> false,
      'path'       => sfConfig::get('sf_upload_dir') . '/directory',
      'mime_types' => 'web_images'
  $this->validatorSchema['image']->setOption('mime_type_guessers', array(
    array($this->validatorSchema['image'], 'guessFromFileinfo'),
    array($this->validatorSchema['image'], 'guessFromFileBinary'),
    array($this->validatorSchema['image'], 'guessFromMimeContentType')

In this case validator will first try fileinfo (which should be available since PHP 5.3.0), then 'file -bi' which should work correctly on *nix platform and only if both failed it will use mime_content_type

Monday, July 27th, 2009

symfony l10n – going further

As you may know symfony offers localized objects out of the box. It gives you an easy way to have different data for different cultures.

Sometimes it is not enough. I needed two localized version of website but with completely different content – everything including users, admin and super admin. Both version were supposed to run under the same domain and to be distinguished just by locale part in the url. I was too lazy and didn’t want to copy applications or projects (moreover, it is a problem in the future, you’ll have to modify each copy). So, I decided to use different databases with exact schema for different cultures.

Here’s guide how to implement this.

Sunday, April 19th, 2009

Problems with index module routing in symfony

I was working on simple symfony website consisting of just one application and one module. Naturally, I wasn’t too creative and choose ‘frontend’ as application name and ‘index’ for module name. When I started to test it on production, it wasn’t working at all except default action. It was giving me 404 error.
After spending some time debugging and logging symfony and mod_rewrite I’ve found out the problem. Rewrite rule was sending me to /index.php/actionname instead of index.php/index/actionname.
The problem was in apache option MultiViews, as soon as I removed it everything started to work as expected. This option tells webserver to search for foo/filename.* if foo/filename wasn’t found.
I had this option enabled in my default virtual host config in my apache distribution and I had never paid any attention to it before.

Wednesday, November 26th, 2008

symfony admin generator – populating create form from filters

symfony has basic CRUD-like admin generator, which allows you to create controls for filtering list results. Naturally, if you have filtered list and press ‘create’ button it would be nice to have new form with populated from filter form fields.

Here’s basic idea how to do it. In my example I have Work entity which has foreign key to Category entity. I have list of works filterable by category id.
To populate category id on work creation form you need to override generated action:

class worksActions extends autoworksActions
  public function executeEdit()
  	if ($this->getRequestParameter('action') == 'create')
  		$filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/work/filters');
  		if (isset($filters['category_id']))

Look into admin generated actions if you want to more clearly understand why we need such code. It is located at cache/admin/dev/modules/autoWorks/actions/actions.class.php

Sunday, October 5th, 2008

Translating symfony validator yaml configs with xgettext

Previously I wrote how to automate routine translation work with xgettext for symfony framework. Unfortunately xgettext cannot parse YAML configs. Obviously you’ll need to translate at least validator error messages. rgettext is not capable too.

I found some solution but I didn’t like it. I wanted to use PoEdit tool to have possibility for automated translation, syncing with sources and easy interface. So I wrote modified task which looks for all validation configs and creates fake php files with messages, which can be parsed by xgettext.

Usage is simple, just copy attached file to symfony/data/tasks in your PEAR directory and run symfony i18n-fake-php app_name. PHP files will be created in validate/ directories. After that you can use xgettext.


Sunday, March 9th, 2008

Rsync using checksum in Symfony

Symfony framework allows easy deployment of the project. All you need to deploy using rsync – is to type symfony sync production (add go to the command for real deploying). It takes connection parameters from config/properties.ini.

However it is using files comparison by size and modification date, default for rsync utility. It isn’t in symfony documentation, but you can easily change rsync parameters to whatever.

Default parameters symfony uses are -azC --exclude-from=config/rsync_exclude.txt --force --delete. To use checksum comparison add the line to [production] in properties.ini:

parameters="-azC --exclude-from=config/rsync_exclude.txt --force --delete --checksum"

Wednesday, March 5th, 2008