"Silently" redirecting to a different controller?

#1
[eluser]ech0[/eluser]
Hi,

I've created a traffic controller, which validates a request and redirects it accordingly. The only problem left, is the URL.

The idea is that if I access <b>/about-us/param1/param2</b>, I see the output of <b>/modules/text/2/param1/param2</b> and the actual URL stays the same (<b>/about-us/param1/param2</b>). So basically, is there a way to keep an initial URL, but access different controller's methods (with an option to pass parameters to them)?

Thank you in advance!

#2
[eluser]abmcr[/eluser]
I think the only way is to manage sessions ....

#3
[eluser]Phil Sturgeon[/eluser]
Could URI routing help in this situation?

#4
[eluser]ech0[/eluser]
[quote author="Phil Sturgeon" date="1245604039"]Could URI routing help in this situation?[/quote]
The problem is that possible routes are generated dynamically (from a database).

#5
[eluser]ech0[/eluser]
How ugly, in terms of speed, is this kind of solution?

<b>routes.php</b>:
Code:
/*
| -------------------------------------------------------------------------
| DYNAMIC ROUTES
| -------------------------------------------------------------------------
*/
$fh = fopen(realpath('routes.csv'), 'r');
while (($data = fgetcsv($fh, 100)) !== FALSE)
// $data[0] = fake URI
// $data[1] = module name
// $data[2] = page id
{    
    // route to controller/index
    $route[$data[0]] = 'modules/'.$data[1].'/index/'.$data[2];
    // route to controller/method/params
    $route[$data[0].'/(:any)/(:any)'] = 'modules/'.$data[1].'/$1/'.$data[2].'/$2';
}
fclose($fh);

#6
[eluser]Phil Sturgeon[/eluser]
It's not brilliant but probably no better than pulling from a database.

I can think of a solution hacking the Router class dude, but i'll have to do it when im near source code with a little more time. I'm sure its possible.

#7
[eluser]ech0[/eluser]
[quote author="Phil Sturgeon" date="1245613137"]I can think of a solution hacking the Router class dude, but i'll have to do it when im near source code with a little more time. I'm sure its possible.[/quote]
I'll stick to my solution for now, but it would be great if you could find a minute or two to put your hands on Router Smile

#8
[eluser]louis w[/eluser]
You might want to check out the Wick Library. I think it's still in beta, but may work for what you need. It allows you to load another controller/method from inside a controller. That way you could move your logic code into a controller instead.

#9
[eluser]Phil Sturgeon[/eluser]
Ahh yes, definitely. Go with Zach's code there. :-)

#10
[eluser]tonanbarbarian[/eluser]
only quickly glanced at this topic so i might be a little off on my idea
how about a slight change in the process instead

why dont you move what were controllers into libraries
then your traffic controller just loads a library and calls a method in the library thereby still following the controller type method
only issue with this is you will probably have to load a CI instance in the library to do most of your work, but that is not a major issue.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.