acHostDependant plugin
The acHostDependantPlugin is a symfony plugin that provide the ability to have different configuration depending on the hostname.
Installation
Install the plugin (via a package)
symfony plugin:install acHostDependantPlugin
Install the plugin (via a Subversion checkout)
svn co http://svn.symfony-project.org/plugins/acHostDependantPlugin/ plugins/acHostDependantPlugin
Activate the plugin in the config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
$this->enablePlugins(array(
'...',
'acHostDependantPlugin',
));
}
}
How to use
Create a new hostname configuration dir with task acHostDependant::createUser
Examples:
$ php symfony acHostDependant::createUser subdomain.mydomain.it
Configuration file is created in %sf_root_dir%/users/subdomain.mydomain.it/config/
Edit the %sf_root_dir%/users/subdomain.mydomain.it/config/settings.yml
Edit the db settings and other settings
Edit file config/databases.yml
edit the "class" and "dsn" line:
all:
doctrine:
class: acHostDependantDoctrineDatabase
param:
dsn: 'mysql:host=localhost;dbname='
Change the parent class in myUser.class.php
class myUser extends acHostDependantGuardSecurityUser
Now you can use this sf settings:
sfConfig::get('sf_ac_host') # the hostname
sfConfig::get('sf_ac_host_dir') # the hostname root folder (es. %sf_root_dir%/users/subdomain.mydomain.it)
sfConfig::get('sf_ac_host_config_dir') # the hostname config folder (es. %sf_root_dir%/users/subdomain.mydomain.it/config)
sfConfig::get('sf_ac_host_uploads_dir') # the hostname uploads folder (es. %sf_root_dir%/users/subdomain.mydomain.it/uploads)
sfConfig::get('sf_ac_host_i18n_dir') # the hostname i18n folder (es. %sf_root_dir%/users/subdomain.mydomain.it/i18n)
Customize i18n for every host
If you need customize i18n for one or more host, you can add this small piece of code in your ProjectConfiguration.class.php or in your ApplicationConfiguration.class.php (ex. frontendConfiguration.class.php)
public function getI18NDirs($moduleName)
{
$dirs = parent::getI18NDirs($moduleName);
if(is_dir(sfConfig::get('sf_ac_host_i18n_dir')))
array_unshift($dirs, sfConfig::get('sf_ac_host_i18n_dir'));
return $dirs;
}
Next create i18n folder in your domain config folder: %sf_root_dir%/users/subdomain.mydomain.it/i18n
and add
Task Command Line