tags:

views:

253

answers:

1

For instance, I have two applications: 'frontend' and 'backend'. I'd like my /web directory to be set up so that '/web/frontend' serves the 'frontend' assets, and '/web/backend' serves the 'backend' assets without having to go modify all the image paths, etc.

+1  A: 

From the Symfony Documentation, doing this in each app's config.php should work [example is showing apps/backend/config/config.php]

sfConfig::add(array(
  'sf_web_dir'      => SF_ROOT_DIR.'/web/backend',
  'sf_upload_dir'   => SF_ROOT_DIR.'/web/backend'.sfConfig::get('sf_upload_dir_name'),
));

For some reason, this method doesn't work. If you take a look at all the variables defined inside sfConfig, you'll notice that you have to change more than sf_web_dir and sf_upload_dir to get things working.

One option would be to manually override the all variables inside sfConfig that point to the web directory inside each app's config.php. To see a list of all the variables, try

<?php echo var_dump(sfConfig::getall()); ?>

Your other option (The way I've done it before) would be to do it in the Apache configuration. Your virtual host settings for backend would look something like

<VirtualHost *>
  ServerName backend.dev
  DocumentRoot "PATH_TO_SYMFONY_PROJECT/web/backend"
  DirectoryIndex index.php
  Alias /sf /usr/local/lib/php/data/symfony/web/sf
  <Directory "/usr/local/lib/php/data/symfony/web/sf">
  AllowOverride All
  Allow from All
  </Directory>
  <Directory "PATH_TO_SYMFONY_PROJECT/web/backend">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

Then you will need to copy backend.php, backend_dev.php [ and possibly index.php if backend is your default enviroment ] to /web/backend, and in each one of those files, change

define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/..'));

to

define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/../..'));

and you should be good. I prefer this method, but if you don't have virtual hosts setup, you might not have this option.

sjobe
You probably already know this... Your symfony install might be somewhere other than "/usr/local/lib/php/data/symfony/web/sf"
sjobe
Wow, thanks for the thorough response sjobe! I'll try it out and then mark this as the correct answer :)
James Skidmore
Worked great. Thanks for your help sjobe, I appreciate it.
James Skidmore