Welcome Guest, Not a member yet? Register   Sign In
Advanced Controller Routing (based on domain)
#1

[eluser]stealthify[/eluser]
Hi all,
First post, but long-time fan of CodeIgniter. While things have been smooth-sailing with CI for my previous adventures, my first question for you guys happens to be a doozy.

The Concept
One CI installation, one database, one application --> routed to from multiple domains --> domain determines the controller to route to (so multiple controllers, multiple languages, multiple views)

I understand that there are probably a few different ways to go about this, but the folder structure I decided upon was:

-----------------------------------------
application/
-- controllers/
---- sites/
------- domain1/
--------- home.php (domain1.com/)
--------- about.php (domain1.com/about)
------- domain2/
--------- home.php (domain2.com/)
--------- about.php (domain2.com/about)
---- home.php (default fallback)
---- about.php (default fallback)
-- language/
---- sites/
------- domain1/
--------- english/
------- domain2/
--------- english/
---- english/
-- views/
---- sites/
------- domain1/
--------- home.php
--------- about.php
------- domain2/
--------- home.php
--------- about.php
---- home.php
---- about.php

-----------------------------------------

I figured this was my best bet, since really all of my configs, helpers, models, libraries, etc will remain the same, no matter which domain I have routed to my CI install.

My Goal
After poking around and exploring how the current routing system works, my plan of action was to determine which domain the code is executing under, and then querying a database to gather some preliminary info on which controller to call (ie: the default fallback if it doesn't exist in the database, or if it is found, the appropriate controller in the 'controllers/sites/' directory).

My Progress
The idea sounds simple enough, and I know how to extract the domain and run a query based on this domain. From there, I also know how to run a check to make sure that the controller exists (ex: controllers/sites/domain1/home.php).

My Question
What I'm stuck on is trying to figure out where I need to start in order to tell CI to call my alternate controller as opposed to the default controller. Will something like this require a modification of the system core? Or is it override-able from my 'application/' folder?

Lastly, do any of you see any pitfalls to using this method? Is there a better way to go about this?

Thanks for the help guys, hope everyone had a great weekend.


Messages In This Thread
Advanced Controller Routing (based on domain) - by El Forum - 07-05-2011, 08:18 AM
Advanced Controller Routing (based on domain) - by El Forum - 07-05-2011, 08:19 PM
Advanced Controller Routing (based on domain) - by El Forum - 07-05-2011, 10:39 PM
Advanced Controller Routing (based on domain) - by El Forum - 07-05-2011, 11:02 PM
Advanced Controller Routing (based on domain) - by El Forum - 07-07-2011, 08:58 AM
Advanced Controller Routing (based on domain) - by El Forum - 07-07-2011, 09:23 AM
Advanced Controller Routing (based on domain) - by El Forum - 07-07-2011, 09:35 AM
Advanced Controller Routing (based on domain) - by El Forum - 07-07-2011, 09:41 AM
Advanced Controller Routing (based on domain) - by El Forum - 07-08-2011, 12:42 AM
Advanced Controller Routing (based on domain) - by El Forum - 07-08-2011, 06:07 AM
Advanced Controller Routing (based on domain) - by El Forum - 07-08-2011, 06:18 AM
Advanced Controller Routing (based on domain) - by El Forum - 07-08-2011, 06:43 AM
Advanced Controller Routing (based on domain) - by El Forum - 07-08-2011, 07:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB