Divide URI segment into 2 parts through routes.php |
[eluser]danishravian[/eluser]
Hi, Is it possible to break the one URI segment into two parts. For example if my URL is: Code: www.example.com/aaa-xxx I want it to route to: aaa controller and xxx as parameter. xxx is variable and it can contain one or more dashes too. Link could be like: Code: www.example.com/aaa-x-z-y-a I tried this in routes.php Code: $route['aaa-(:any)'] = "aaa/$1"; It goes to aaa controller, but it is not passing any variable. Please let me know how can I do this? Thanks
[eluser]louisl[/eluser]
You can to do that in the controller, grab $this->uri->segment(1) then break it up as you need, also take a look at the CodeIgniter's _remap() function.
[eluser]danishravian[/eluser]
I am familiar with remap, but problem with remap is that it will go to default controller. But i want to send it to some other controller.
[eluser]louisl[/eluser]
Please explain what you are trying to achieve, what are you expecting to happen with the variables changing in the urls?
[eluser]danishravian[/eluser]
aaa will be my controller... and second part is a variable, which I will search in database and on the basis of that variable, I will display the results ..
[eluser]louisl[/eluser]
Is there a reason you cant do www.example.com/aaa/x-y-z ? Do you have other controllers or is the intention to have one controller for the whole site? So urls could be www.example.com/x-y-z, www.example.com/a-b-c etc?
[eluser]danishravian[/eluser]
There are other controllers as well and i have to use dash for seo purpose and its client's requirement
[eluser]CroNiX[/eluser]
Code: //pass it to a method in your controller, not just the controller (unless using _remap())
[eluser]louisl[/eluser]
Nice solution CroNIX, I was going to suggest this:- Code: //$route['aaa-(:any)'] = "aaa/$1";
[eluser]danishravian[/eluser]
there is some modification in the structure. actually whenever url will be something like aaa-x-y-z, then I am sending it to a controller and passing aaa and x-y-z as two parameters. Code: class bbb extends CI_Controller { and I am using this in route.php file Code: $route['aaa-(:any)'] = "bbb/aaa/$1"; So the problem here is, uri segment 2 is empty and uri segment 1 contains both the parameters. But uri 1 should contain aaa and uri 2 should have x-y-z. How can I do this? |
Welcome Guest, Not a member yet? Register Sign In |