开发者

Codeigniter with different domains

I'm looking to try and use codeigniter with different domains all using the same code structure, within the code igniter framework.

The libraries, models and database should be the same across all the domains, the only difference should be the controllers and views that are used.

Preferably I would like to have a开发者_如何学Python setup similar to this:

controllers/domain1.com/index.php
controllers/domain2.com/index.php
controllers/domain3.com/index.php

Does anyone have any experience modifying code igniter to work in this way?


Take a look at the loader class page in the manual and scroll down to the Application "Packages" part. Combine this with the part of running Multiple Applications you should be able to be running multiple sites, with the same models and configs and avoid duplicating your code.


There is a manual page that describes how do you achieve this. Consult with Running Multiple Applications with one CodeIgniter Installation.

The only difference is that it looks like you'll have to duplicate your models/configs as well.


In my experience I need to build a system on a different subdomain, since the default domain has an existing base codeigniter and it was not design to handle multiple domains or subdomains.

And part of my goals are:

  • use the existing shared core objects in dir config, core, helpers and libraries.
  • and the existing public dir files, but separate images/mysubdomain/* and other dirs/subdomain/*

And so this is what I have done.

  • I've modified router.php in the same config dir and made a condition that routed a default controller in a separate dir inside mysubdomain/default if subdomain===true
  • ie. /controllers/mysubdomain/default.php
  • With a separate base controller that extends the main Controller inside /controllers/mysubdomain/.
  • Then mysubdomain are defined (ie models/mysubdomain/* and views/mysubdomain/* in all my controllers in mysubdomain.

and this works perfectly as I need it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜