Blog

How to customize the directory structure in symfony 1.1

Symfony Live 2010 Paris Conference

« Back to the Blog

Categories

Feeds

feed Posts feed

comments feed Comments feed

symfony training
Be trained by symfony experts
Jul 22: Paris (1.2 + Doctrine - Français)
Aug 19: San Francisco (1.2 + Doctrine - English)
Sep 23: Paris (1.2 + Doctrine - Français)
Oct 21: Nantes (1.2 + Doctrine - Français)
Nov 18: Paris (1.2 + Doctrine - Français)
and more...

Archives

Creative Commons License This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.

One of the great advantage of using a framework is the consistent structure it gives across your projects. All projects share the same coding standards, and also the same directory structure. This structure allows several developers to work on the same project at the same time. But it also enhances the maintainability of the developed applications. When someone ask you to maintain a symfony project that you haven't developed initially, you know where all the files are stored and you can start hacking right away.

But sometimes, you need to be able to customize the directory structure provided by symfony. Let's take two very different examples.

First, let's say you host your symfony project in a shared host environment, where the web root directory is named public_html. By editing the ProjectConfiguration class, it's very easy to change the default web root directory from web to public_html as show below:

// config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()

  {
    $this->setWebDir($this->getRootDir().'/../public_html');
  }
}
 

Let's take another example. Your symfony project is now hosted by a very big company with strict security rules. They don't allow your applications to write on the disk except for some specific directories (/tmp for example). As symfony only writes in two directories (cache, and log), it's very easy to update the ProjectConfiguration class again to move these directories under /tmp:

// config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()

  {
    $this->setCacheDir('/tmp/myproject/cache');
    $this->setLogDir('/tmp/myproject/log');
  }
}
 

The setCacheDir() method not only changes the sf_cache_dir constant but also all the cache related ones: sf_app_base_cache_dir, sf_app_cache_dir, sf_template_cache_dir, sf_i18n_cache_dir, sf_config_cache_dir, sf_test_cache_dir, and sf_module_cache_dir.

And last but not least, as the configuration classes are also used for the symfony CLI, all these customization are also active for all the bundled symfony tasks and your specific tasks.

Thanks to the new configuration classes of symfony 1.1, the configurability of the framework has never been so easy.

Comments comments feed

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.