Shimsham84 Shimsham84 - 1 month ago 6
PHP Question

_remap or URI Routing in codeigniter

I am currently looking into the PHP Framework Codeigniter and understand the main concepts so far until the Controllers section about _remapping. I have a understanding how _remapping overwrites the behaviour of controller methods over the URI eg from www.example.com/about_me to www.example.com/about-me. What i would like to hear is peoples opinions on what to use- _remapping method or the URI Routing method? Im only asking this as when researching these methods and someone has been troubled on remapping functions, they have been directed to use URI Routing.

So..

1) What is the main common method to use and the pro's over the other one?
2) Is it best to use URI Routing for PHP5 CI version 2 onwards?

I would be grateful to hear your opinions!

Answer Source

Assuming you do not want to use the index (i.e. http://www.yourdomain.com/category) action of your Categories controller, you can use routes.

$route['category/(:any)'] = 'category/view/$1';

Then you simply need a View action within your Category controller to receive the Category name, i.e. PHP.

http://www.yourdomain.com/category/PHP

function View($Tag)
{
    var_dump($Tag);
}

Should you still want to access your index action within your controller, you can still access it via http://www.yourdomain.com/category/index