CodeIgniter Forums
[split] Routing Question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: [split] Routing Question (/showthread.php?tid=61944)



[split] Routing Question - rahendz - 06-02-2015

Glad to hear an update from CI 2.x Series. And wanna ask about routing. First, i dunno which thread exactly to ask this question, so sorry if i got wrong thread here. As i'm using CI 2.2.1 and this is a thread that newest from it's series so i ask here.

Second, sorry for my bad english. I'm from indonesia and still understanding to develop using this framework.

And here's my question, i'm playing with route. Like this below :

Code:
$route['(:any)'] = 'smpht/index/page/$1';

it explained that any first segment will routed to smpht controller, index method, and page as first param. How i can tell the CI to search controller first, than if there's no controller it will routed. like example below :

Code:
http://localhost/lorem

first it will find 'lorem' controller, when 'lorem' controller doesn't exist it will routed to :

Code:
http://localhost/smpht/index/page/lorem

if there's anyone knows the answer, i'm totally happy to hear the solution. thanks before.


RE: [split] Routing Question - dbsolde - 06-02-2015

Hello,
Have you tried to use _remap function?
Just check the first segment of the url then you can make a condition where you want to pass them.

public function _remap(){
$segment_1 = $this->uri->segment(1);
$segment_2 = $this->uri->segment(2);

switch ($segment_1) {
case 'lorem':
//condition here..
break;
}
}

hope it help Smile