Difficulties in setting up a custom 404 page. |
[eluser]duartix[/eluser]
I’m using CodeIgniter 2.1.4 I’m trying to show a custom error 404 page, but it’s not loading when I type a non existent URI. my routes.php is as follows: Code: | There area two reserved routes: I’ve also defined views/error_404.php like this: Code: <div class="centeredImage"> However what shows is a very sober Error 404 page. :-( Shouldn't it be this simple? TIA.
[eluser]Pert[/eluser]
What you are defining in routes.php are controllers, not views. So you need to create error_404 controller, then use that to load your error_404 view.
[eluser]duartix[/eluser]
[quote author="Pert" date="1377780827"]What you are defining in routes.php are controllers, not views.[/quote] That's a good tip, I had no idea, thank you. [quote author="Pert" date="1377780827"]So you need to create error_404 controller, then use that to load your error_404 view.[/quote] OK, basically I created this: Code: class error_404 extends CI_Controller { and it worked like a charm on execution ! Thanks a million! However, if I manually type a non existent URI, it will still shows the default 404 page. :-( Is there some simple workaround?
[eluser]gummiforweb[/eluser]
Extend a custom controller and setup the custom 404 page. 1). Create file inside /application/core/MY_Controller.php Code: <?php 2). Instead of extending CI_Controller, extends MY_Controller on all your controller inside the controllers folder. 3). You are done. Now, if a method doesn't exits inside the controller class, it'll run the _parse404() methods, which will rander the my_404_page.php view file inside the view folder. Reference: Remapping Function Calls: http://ellislab.com/codeigniter/user-gui...#remapping Extending Core Class: http://ellislab.com/codeigniter/user-gui...asses.html
|
Welcome Guest, Not a member yet? Register Sign In |