多站点Codeigniter项目的最佳方法? [英] The best approcach for Multi-Site Codeigniter projects?

查看:99
本文介绍了多站点Codeigniter项目的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您花时间阅读这篇文章。



这里是我想要的:



我会有一个主服务器将保存客户的包信息,他们订购的主题和他们从我的市场附加的a_ds。



我不希望他们的网站是一个子域,而是他们自己的域,它将由我在一个共享的环境中托管。



现在,我想以这种方式设置我的CI项目,这些都会发生。每个单独的客户端都将被赋予自己的项目空间和数据库,但我希望他们的特定项目从我的数据库/ CI函数中导出他们的设置。



我知道我写得很糟糕,但即使谷歌失败了我。

解决方案



您是否打算在您的服务器中从一个CodeIgniter源运行这些大量的网站,应用程序配置取决于访问哪个域?



如果是这种情况,然后这里是一个选项可用于你的头顶:



组织 application / config 像这样:

  application / 
config /
domains /
foo.com /
database.php
config.php
bar.net/
database.php
config.php
baz.org/
database .php
config.php

这些 / domains / * /(database | config).php 文件包含仅特定域的配置(您必须以某种方式生成)。



示例:

  //在database.php文件中
return array(
'username'=>'client1',
'password'=>'password!',
'database'=>'client1_db'
);

//在config.php文件中
返回数组(
'base_url'=>'http://baz.org'
);

然后它只是根据请求中使用的域包括正确的文件: p>

application / config / database.php 中:

  $ client_vars = include __DIR__。 '/ domains /'。 $ _SERVER ['HTTP_HOST']。 '/database.php'; 

/ *验证$ client_vars以确保客户端不会覆盖任何重要的。抛出错误以通知客户端。 * /
$ db ['default'] = array_replace($ db ['default'],$ client_vars);

/ *其余的数据库设置。 * /

application / config / config.php

  $ client_vars =包含__DIR__。 '/ domains /'。 $ _SERVER ['HTTP_HOST']。'/ database.php'; 

/ *验证$ client_vars以确保客户端不会覆盖任何重要的。抛出一个错误通知客户端* /
$ config = array_replace($ config,$ client_vars);

/ *其余配置设置* /

这是一个粗略的想法的一个可能的解决方案,虽然这不是很安全。只有两美分。


Thanks for taking the time to read this.

Here's what I want:

I will have a main server, it will hold the client's package info, the themes they've ordered and a_ds they have attached from my marketplace.

I don't want their site to be a sub-domain, rather their own domain and it will be hosted by me in a shared environment.

Now, I want to set up my CI project in such a way, that these will happen. Each individual client will be given their own project space and database but I want their particular projects to derive their settings from my database/CI functions.

I know I wrote terribly, but even Google failed me on this. You guys are my last hope.

Thanks in advance!!

解决方案

Do you intend to run these multitude of sites from one CodeIgniter source in your server, with application configurations varying depending on which domain is accessed?

If that is the case, then here is an option available for you off the top of my head:

Organize the varying configurations in application/config like this:

application/
    config/
        domains/
            foo.com/
                database.php
                config.php
            bar.net/
                database.php
                config.php
            baz.org/
                database.php
                config.php

Each of these application/config/domains/*/(database|config).php files contain the configurations specific only for that particular domains (You have to generate these somehow).

Example:

  //In database.php files
  return array(
       'username' => 'client1',
       'password' => 'password!',
       'database' => 'client1_db'
  );

  //In config.php files
  return array(
       'base_url' => 'http://baz.org'
  );

Then its just a matter of including the right file depending on the domain used in the request:

In your application/config/database.php:

  $client_vars = include __DIR__ . '/domains/' . $_SERVER['HTTP_HOST'] . '/database.php';

  /* validate $client_vars to ensure that client is not overriding anything important. Throw an error to inform client. */
  $db['default'] = array_replace($db['default'], $client_vars);

  /* Rest of DB settings. */

In your application/config/config.php:

  $client_vars = include __DIR__ . '/domains/' . $_SERVER['HTTP_HOST'] .'/database.php';

  /* validate $client_vars to ensure that client is not overriding anything important. Throw an error to inform client */
  $config = array_replace($config, $client_vars);

  /* Rest of config settings */

This is a rough idea of a possible solution, though this is not very secure at all. Just two cents.

这篇关于多站点Codeigniter项目的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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