0
votes

I have a small problem with routing.

My routes:

$route['category/(:any)/(:num)'] = "site/index/$2"; //not working
$route['category/(:any)'] = "site/index"; //not working
$route['category/(:any)/(:any)'] = "site/view/$2"; // working
$route['Search'] = "site/search"; // working

What I want: http://example.com/category/Home - call site/index function http://example.com/category/Home/2 call site/index function with parameter $2 I'm geting 404 erro at those 2 rules.

What I tried was to echo the parameter of category/(:any)/(:num) and it echoed it. This echo was inside the index function. The views adn models exists in the paths I declared. The index page itself wouldn't work without it. So I think the problem has to be in routing

The most interesting thing is that when I change the category/(:any) route to site/view it is working but when I set there site/index it is not working. Even if I set there only site .

1
remove your route and retry. It should automaticly route to the correct action. As explained here, default behaviour is example.com/class/function/id/. - Brewal
I tried to remove the route and add it again but nothing happend. If the route is not there it call the site/view function - DeiForm
Ok... I see what's your problem - Brewal
Well actually, all your routes are weired. ie : $route['(:any)'] will point to site. That means, whatever you type, you go to site. This is massive duplicate content. - Brewal
Yeah your routes are all kinds of messed up I don't even know where to start. - Wesley Murch

1 Answers

0
votes

I think what you are trying to do is to have your site class as "default controller". Just try this :

$route['default_controller'] = "site";
$route['(:any)'] = "site/view/$1";
$route['(:num)'] = "site/index/$1";

I don't really know what you are trying to do with your site/view/$1 and site/index/$1 it will work like this :

example.com/someaction will match $route['(:any)'] and will call the view method of the site controller with someaction as a string parameter.

example.com/2 will match $route['(:num)'] and call the index action of the site controller with 2 as an integer parameter.

example.com/admin will call the index action of the admin controller

example.com/admin/category will call the category action of the admin controller