Welcome Guest, Not a member yet? Register   Sign In
Dynamic default controller (routing question)
#1

[eluser]La Loutre[/eluser]
Hi all,

I'm sorry to create a new thread on routing question, but I've been reading this forum for hours without finding a correct solution for my simple problem. Here it is : I'm in charge of a website which can start either with a page A (managed by Controller A) or a page B (manage by Controller... B), depending on the moment in the year.
I thought the best way is to keep a switch (A or B) in a database parameter table. But I don't know where to put the switch code :
- the route configuration file (default_controller) : I need something dynamic
- a hook : how do I chain to the good controller after it ?
- a base controller : I can't imagine a good way to chain controllers (and that's pretty normal in a MVC application)
- something else ?

Thank you !
#2

[eluser]xwero[/eluser]
I would go for d : something else and that would be a controller that acts as a router. You set the controller as the default controller and then you write
Code:
class default extends Controller
{
   function index()
   {
       if(date('z') <= date('z',mktime(0,0,0,6,1,date('Y')))
       {
           redirect('a/a');
       }
       else
       {
           redirect('b/b');
       }
   }
}
#3

[eluser]La Loutre[/eluser]
Thank you xwero, that's a pretty simple solution which I didn't figure out... Rather than chaining Controllers, http redirection.
#4

[eluser]xwero[/eluser]
When i have new tools i also use the most impossible ways to get something done but simple is always the best solution Smile
#5

[eluser]taewoo[/eluser]
Very elegant solution. No need for routing. Bravo.
#6

[eluser]ontguy[/eluser]
Nice solution. I think that code could be put in routes.php to switch the default route.




Theme © iAndrew 2016 - Forum software by © MyBB