The symfony Cookbook

How to customize the default Directory Structure

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


About

You are currently reading "The symfony Cookbook" which is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License license.

Master symfony

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Books on symfony

Learn more about symfony with the official guides.
books.sensiolabs.com

L'audit Qualité par SensioLabs

200 points de contrôle de votre applicatif web.
audit.sensiolabs.com
symfony training
Be trained by symfony experts
Feb 21: Köln (Getting Started with Symfony2 - English)
Feb 27: Köln (Mastering Symfony2 - English)
Mar 05: Köln (Web Development with Symfony2 - Deutsch)
Mar 05: Montreal (Web Development with Symfony2 - English)
Mar 05: Montreal (Getting Started with Symfony2 - English)
and more...

Search


powered by google
You are currently browsing "The symfony Cookbook" in English for the 1.2 version - Switch to version: - Switch to language:
Creative Commons License This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.
Translation of this work into another language is explicitly allowed.
This version of symfony is not maintained anymore.
If some of your projects still use this version, consider upgrading as soon as possible.

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.

Questions & Feedback

If you find a typo or an error, please register and open a ticket.

If you need support or have a technical question, please post to the official user mailing-list.