Welcome Guest, Not a member yet? Register   Sign In
mod_rewrite removing function index in specific Controller
#1

[eluser]Unknown[/eluser]
I have Controller "Article" and function "index" which receive one string parameter so link look like:

www.site.com/article/index/some-string

I would like to remove "index" to get only this:

www.site.com/article/some-string

Anyone can help how to do that?
#2

[eluser]victorche[/eluser]
Open /application/config/routes.php
And add the following line:
Code:
$route['article/(:any)'] = "article/index/$1";
#3

[eluser]WanWizard[/eluser]
Check the manual and read up on routes.

Something like:
Code:
$route['article/(:any)'] = "article/index/$1";
#4

[eluser]Unknown[/eluser]
Hmmm but I can't now call another function in that Controller.

www.site.com/article/delete/1234 calls index function with 2 parameters.

Is there some mechanism to recognize function and dont call index width that parameter?
#5

[eluser]hugle[/eluser]
Hello

you could make some exceptions, for example, add one route for delete:

Code:
$route['article/delete/(:num)'] = "article/delete/$1";  
$route['article/(:any)'] = "article/index/$1";

:num - stands for numbers as you understood already Smile

Good luck
#6

[eluser]WanWizard[/eluser]
You can also use the _remap() method to capture all calls to the controller, and in there check if an existing method is called. If not, call index().

In that case you don't need routes.




Theme © iAndrew 2016 - Forum software by © MyBB