URI segment in index function? |
[eluser]Sam Granger[/eluser]
Hey guys! I have a category class controller. Code: <?php Currently if I go to http://domain.com/index.php/category/2 I get a 404. What am I doing wrong?
[eluser]xwero[/eluser]
If there are no segments the url routes to the default controller, in the routes.php file, and the default method, hardcoded in the router. This works fore a single segment too but from the moment two segments are found the router assumes the first segment is the controller and the second the method. So to make your url possible you need to use routing. If the controller has only one method then you can do Code: $route['controller/(.+)'] = 'controller/index/$1';
[eluser]TheFuzzy0ne[/eluser]
...Or you can call your URL like this: http://domain.com/index.php/category/index/2 (Yuck) I would suggest that you create another method, perhaps show_category or something like that, and use the index method to alias it. Basically, it will only alias it when there are no arguments, but from then on, the user will be using show_category. Code: function index()
[eluser]xwero[/eluser]
TheFuzzy0ne http://domain.com/index.php/category/show_category/2 looks even uglier. There are two options to make the url work, with routes or with _remap. _remap is basically routing on class level. |
Welcome Guest, Not a member yet? Register Sign In |