![]() |
detail page problem, does not exists - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: detail page problem, does not exists (/showthread.php?tid=42876) |
detail page problem, does not exists - El Forum - 06-22-2011 [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 detail page problem, does not exists - El Forum - 06-22-2011 [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 ![]() detail page problem, does not exists - El Forum - 06-22-2011 [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 detail page problem, does not exists - El Forum - 06-22-2011 [eluser]danmontgomery[/eluser] http://ellislab.com/codeigniter/user-guide/general/urls.html http://ellislab.com/codeigniter/user-guide/general/routing.html detail page problem, does not exists - El Forum - 06-22-2011 [eluser]Michal1[/eluser] edit: Oh I got it now thanks. |