English 中文(简体)
多个动态域,使用单一编码装置
原标题:Multiple Dynamic Domains Using ONE Codeigniter Installation

我的工作之一是管理遍布全国各地的58个场所。 他们各自都有自己的领域,都在同一媒体寺院的“虚拟服务”。 这些网站约有19页,每一页使用相同的html/cs/php代码。 这些图像从一个中央存放处向每个网站提供,每个专题都有不同的文件夹。

我想做的是安装一个单一的C2号安装装置,包括申请夹,因为各站点之间的一切都储存在数据库中。 只要我能够给控制员一个独一无二的财产号码(我希望我能够在他们查阅每个领域的索引.php网页时这样做),那么我的所有地点都将做罚款。

在我宣读的所有答复中,建议是复制申请夹,并且只是重新使用核心。 对我来说,最好还是再利用申请夹。 然后,当我作修改时,它将赶到所有地点,而我无需打到58页。

这是可能的吗?

最佳回答

如果所有档案都相同,而且数字之间唯一变化的是数据库的数据,那么你可以这样做:

  • Point all domains to your docroot for the CI install
  • in your index.php, determine which db connection you need to use for the currently requested domain:

 // index.php
$domain = $_SERVER[ SERVER_NAME ];
switch ($domain)
{
    case  www.firstsite.com :
        $this->load->database( firstsitedb );
        break;
    case  www.secondsite.com :
        $this->load->database( secondsitedb );
        break;
    default:
        show_error( No Site Found );
        break;
}

** 本文件迟交。

如果他们各自使用同一数据库,而且你需要能够使用你询问中的变量,那么就只是根据开关/案件而不是装设一个不同的数据库确定一个不变的。 然后,在您的问询中,你可以始终使用这一常态。

 // index.php
$domain = $_SERVER[ SERVER_NAME ];
$site_id = 0; // default
switch ($domain)
{
    case  www.firstsite.com :
        $site_id = 1;
        break;
    case  www.secondsite.com :
        $site_id = 2;
        break;
    default:
        show_error( No Site Found );
        break;
}
define( SITE_ID , $site_id);
问题回答

With Codeigniter 2.2, the index.php now allows the setting of a config array item (the feature is documented in that file). So it is possible to save the requested domain as a site variable in effect by doing this:

$assign_to_config[ site_domain ] = empty($_SERVER[ SERVER_NAME ]) ? default.dev : $_SERVER[ SERVER_NAME ];

之后,你可以把这个网站与一个数据库连接起来,以收集必要的内容和内容;主题观点等。





相关问题
PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

What s the proper MVC way to do this....?

Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I m actually using Kohana). I m new to MVC and don t want to get this wrong... so I m wondering if i have ...

Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

CodeIgniter adding semicolons

How do I stop CodeIgniter adding semicolons ; to data sent via POST that contains ampersand &? For example it is converting "a=1&b=2&c=3" into "a=1&b;=2&c;=3". From looking on the forums ...

Best way to make Admin pages in CodeIgniter?

I m working on an app in CodeIgniter, and I want to have admin pages for several of the objects in the application, and I m wondering what would be the better way to put these into an MVC structure. ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签