detail page problem, does not exists |
[eluser]Michal1[/eluser]
Hi guys I have a little problem with controllers in my project. I am trying to learn Code Igniter as much as possible so I have decided to create a little cms. However there is a problem in detail page when than it says it does not exists. Here is my code: This is my siteview (which is the mainpage view) Code: <?php if (isset($games)): foreach ($games as $row) : ?> Of course I have a controller created for this but there is no problem with that. The problem is with the line Code: <?php echo anchor('detail/'.$row->id,'Run'); ?> when I click on some I get for example: Code: http://127.0.0.1:8888/novy/index.php/detail/27 So then I have a "detai" controller and inside of it: Code: class Detail extends Controller And then I have a detail_view and inside: Code: <?php if (isset($game)): foreach ($game as $row) : ?> However when I click on some anchor in site_view I get 404 Page Not Found The page you requested was not found. Why is that? it seems everything is right. Thank you Michael
[eluser]danmontgomery[/eluser]
The index() method is only called when the only parameter CI has is the controller (or it has no parameter, and determines the controller from the default_controller set in routes.php). If you want to call the index() method and pass it parameters, you have to explicitly tell CI this: Code: <?php echo anchor('detail/index/'.$row->id,'Run'); ?> Naturally, you probably don't want the /index/ in your URL, which is what routes are for. So, open up config/routes.php and add: Code: $route['detail/(:num)'] = 'detail/index/$1'; Voila ![]()
[eluser]Michal1[/eluser]
Oh thank you it works now. But I still do not get why it has to be like that. Could you please explain it little bit more easier to me? I would like to understand it. Because I tried to delete detail controller and instead of that I created a function "detail" in the site controller. so it then was like: Code: class Site extends Controller and then when I had in my site_view this: Code: <?php echo anchor('detail/'.$row->id,'Run'); ?> Thank you
[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui.../urls.html http://ellislab.com/codeigniter/user-gui...uting.html
|
Welcome Guest, Not a member yet? Register Sign In |