为多个域配置 symfony 项目 [英] Configure symfony project for Multiple Domains

查看:21
本文介绍了为多个域配置 symfony 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个用 PHP Symfony 框架开发的产品.我们现在有几个客户,我们为他们维护不同的代码库和数据库 (MySql).

We have a product developed in PHP Symfony framework. We have couple of clients right now for whom we are maintaining different code base and databases (MySql).

他们使用 client1.myproduct.com 和 client2.myproduct.com 等子域访问各自的代码库

They access their respective code base using subdomain like client1.myproduct.com and client2.myproduct.com

现在我们想为两个客户端创建一个单一的代码库,并且只在不同的子域中为它们保留不同(在逻辑方面)的文件.

Now we want to make a single code base for both the clients and only keep files which are different (in terms of logic) for both of them in separate subdomains.

因此,两个子域都将指向相同的代码库,但会在需要时访问各自子域中的文件,即当两个客户端的某些功能的逻辑不同时.

So both the subdomains will point to the same code base but will access files from their respective subdomains whenever required i.e. whenever logic is different for some feature for both the clients.

谁能建议最好的方法是什么?

Can anyone suggests what is the best way to go about this?

推荐答案

sites: [foo.com, bar.co.uk, www.mike.es]

sites: [foo.com, bar.co.uk, www.mike.es]

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

// get the domain
$domain = $_SERVER['SERVER_NAME'];

// get rid of www, com, es etc ...
foreach(array('www.', '.com', '.es', '.co.uk') as $crap) {
    $domain = str_replace($crap, '', $domain);
}
$confs = array(
    'foo' => 'somefoo',
    'bar' => 'somebar',
    'waz' => 'andwazconfig'
);
$cfg = (!empty($confs[$domain])) 
    ? $confs[$domain] 
    : 'default';

$configuration = ProjectConfiguration::getApplicationConfiguration($cfg, 'prod', false);

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

// End of index.php

希望能帮到你

这篇关于为多个域配置 symfony 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆