CodeIgniter Forums
Shared controllers between domain and subdomain - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Shared controllers between domain and subdomain (/showthread.php?tid=59545)



Shared controllers between domain and subdomain - El Forum - 10-18-2013

[eluser]Unknown[/eluser]
Hi everyone.

I have a big doubt regarding domain and subdomains..

I have a domain and 3 subdomains..

example.com -> www
bla.example.com -> www/bla/
ble.example.com -> www.ble/
bli.example.com -> www.bli/

The domain aims for the www folder, bla subdomains aims to bla folder inside www folder.

My question is bla,ble,bli sites will be quite similiar, same controllers, same models.. same everything, the only thing that will change on them is the type of category..something like

bla.example.com
category = "a";

ble.example.com
category = "b";

bli.example.com
category = "c";

All queries are going to be the same, but in each site they will search for that specific category.. My question is.

Do i need to install codeigniter in each of the subdomain folder, and copy paste all the project and just change the variable that's defining the category?

Do i have the possibility to have 1 install only of codeigniter and define a variable for each subdomain i am going to?

I need some sugestions,

Best Regards.




Shared controllers between domain and subdomain - El Forum - 10-19-2013

[eluser]CroNiX[/eluser]
What you could do is symlink the directories for each sites directory structure to point to a common codebase elsewhere on the system. And then in the application check the value of $_SERVER['HTTP_HOST'] or something to determine what server it's being run on and load the appropriate things for that site.

so maybe

/home/codeigniter <-your real CI installation
/home/codeigniter/system
/home/codeigniter/application
/home/codeigniter/index.php <-set environment or define variable based on $_SERVER['HTTP_HOST'] value
/home/site1/system (symlink points to /home/codeigniter/system)
/home/site1/application (symlink points to /home/codeigniter/application)
/home/site1/index.php (symlink points to /home/codeigniter/index.php)
/home/site2/system (symlink points to /home/codeigniter/system)
...

I do this for over 175 real estate agent websites. They all run off of a single codebase on the same server, and just load the appropriate data for the real estate agent base off of the domain name and controller it's being called from. It's kind of a multisite CMS.


Shared controllers between domain and subdomain - El Forum - 10-19-2013

[eluser]CroNiX[/eluser]
Another possible option is to just set the "application" and "system" directories to a common one in index.php. And then just copy the index.php to each site, which would be the only file you'd need in the dir.

In index.php:
$system_path = '/home/codeigniter/system';
$application_folder = '/home/codeigniter/application';