Codeigniter showing "404 page not found" error, code looks correct |
[eluser]MikeW1911[/eluser]
I am using Codeigniter 2.1.0 and following this tutorial shopping cart tutorial The previous tutorials in the series worked fine, but when I load the controller for this tutorial, Codeigniter gives me the "404 page not found" error. I hope it's not a silly mistake "shop.php" controller: Code: <?php "model_products.php" model: Code: <?php "view_products.php" view: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
[eluser]MikeW1911[/eluser]
Thank you, that worked! Why doesn't public function __construct() work properly for controllers?
[eluser]Aken[/eluser]
The way CodeIgniter calls controllers based on the URL requires an index() method if you're accessing a controller's "home" page, like in your case. The constructor is a magic method run every time the class is instantiated, and any code inside of it is run before any method called. You should move the index-specific content to your index() method, and leave the constructor with just "parent::__construct();" in it. Read more about CI controllers in the user guide, and PHP Object-Orientated Programming if you want to understand more (which is recommended if you want to use this framework). |
Welcome Guest, Not a member yet? Register Sign In |