An Update to Dynamic Subdomains for Symfony 1.1

In a previous article, we saw how easy it was to enable dynamically loaded Symfony applications via subdomains. Well, the format for the controller files has changed slightly in Symfony 1.1 (most notably, the “SF_” constants have been banished) so here’s an updated version of the previous example index.php front controller:

<?php
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');

// get the domain parts as an array
list($tld, $domain, $subdomain, $subdomain2) = array_reverse(explode('.', $_SERVER['HTTP_HOST']));

// determine which subdomain we're looking at
$app = ($subdomain == 'staging') ? $subdomain2 : $subdomain;
$app = (empty($app) || $app == 'www' ) ? 'frontend' : $app;

// determine which app to load based on subdomain
if (!is_dir(realpath(dirname(__FILE__).'/..').'/apps/'.$app))
{
  $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
}
else
{
  $configuration = ProjectConfiguration::getApplicationConfiguration($app, 'prod', false);
}

sfContext::createInstance($configuration)->dispatch();

For the full details of how this file works, be sure to read the previous article.



Find This Article Useful?

  • Share/Save This Entry



Related Articles


About this entry