4

We are planned to host a single CMS for the multiple sites.

Is there are way in YII we can do that, The idea is simple we want to share single application and single database for all the domains but we will let them choose the different themes for the different website.

By website I mean totally different Domains.

What other setting will we have to do to point all the domains to single server ?

Edit::

I don't want the different serve directory for each domain. what I want to do it, keep the installation only one.

i.e. /server/www/master

then all the domains

a.com, b.com, c.com read the same dir "/server/www/master" and same DB. and records get filer on the base of site.

4

2 回答 2

3

我已经用 Yii 做到了,所以是的,这是可能的。

在您的 Apache 设置中,确保将所有域名指向同一个目录(使用 ServerAlias - http://httpd.apache.org/docs/2.2/mod/core.html#serveralias)。

在我的数据库中,我为每个网站创建了一个包含一行的表,将域名存储为字段之一。

在我的 ApplicationConfigBehavior.php::beginRequest (对每个请求都执行)中,我做了这样的事情:

/**
     * Load configuration that cannot be put in config/main
     */
    public function beginRequest()
    {
        if(empty(Yii::app()->session['community'])){
            $current_community = Community::model()->with(array(
                'communityHosts'=>array(
                    'joinType'=>'INNER JOIN',
                    'condition'=>'`communityHosts`.hostname= :hostname',
                    'params' => array(':hostname' => $_SERVER['SERVER_NAME'])
                ),
            ))->find(); 
            Yii::app()->session['community'] = serialize($current_community);
        }
        else{
            $current_community = unserialize(Yii::app()->session['community']);
        }

        if(!empty($current_community)){
            Yii::app()->name = $current_community->name;
            Yii::app()->params['currentCommunity'] = $current_community;
            Yii::app()->language = $current_community->language;
        }
        else{
            //TODO: Throw error
            session_unset();
            die('Hostname ' . $_SERVER['SERVER_NAME'] .' not found');
        }


    }

基本上说,在我的数据库中查找此服务器名称,获取当前的“社区”(我的站点),并将所有设置(主题、站点名称等)存储在会话中。

对您来说,确切的查询可能不一样。这只是给你一个大致的想法。使其适应您的数据库架构,或者您存储每个网站的设置。

于 2013-10-06T13:16:45.330 回答
1

在apache虚拟主机文件中,设置站点名称

SetEnv SITE_NAME "CMSA"

使用在代码中获取站点名称

defined('SITE_NAME') || define('SITE_NAME', ( getenv('SITE_NAME') );

在配置中使用常量并根据站点过滤您的记录。

同样的方式也可以声明主题。

于 2013-10-06T10:30:48.137 回答