404 page - more info, please |
[eluser]victorche[/eluser]
One of the changes in the changelog says something about more flexible and powerfull way of dealing with custom not found/404 error page. Until now (in 2.0 beta core) I was dealing with this with MY_Router.php file. Can someone give me an example ... of how can I make a custom 404 page (with a proper view, which looks like the rest of the design and offers links in the page for some main parts of the site). With MY_Router.php I had really powerfull solution but if it is really an option in CI, I prefer not to extend the code and to keep it clean ... Thanks in advance ! EDIT: Maybe we should wait for some updates in the user guide ... As I can see, it is still not complete and maybe it is a work in progress. There are even some missing parts, like: http://ellislab.com/codeigniter/user-gui...lding.html
[eluser]Twisted1919[/eluser]
Create a controller, make it load an error view, then give the controller name to the "404" route.
[eluser]victorche[/eluser]
[quote author="Twisted1919" date="1296410771"]Create a controller, make it load an error view, then give the controller name to the "404" route.[/quote] Thanks, but can you be a little bit more specific? I want to be able to redirect to it, when ... for example I need a way to redirect to this 404 page, when there is no id in the database, for a news controller for example... I mean, if I have /news/12 (existing news) - it will be displayed But if I have /news/13f45qa (non existing id in the db) - then redirect to 404 I am making the check for a valid id in the controller and according to this - sending the user to 404
[eluser]Twisted1919[/eluser]
What you don't understand is that, show_404(); is the function that is called automatically by codeigniter when the page isn't found. Therefore, if you create a custom 404 page as i pointed in the previous post, it will be loaded when a user looks for a page that doesn't exists so you don't have to do additional steps. Also, if you call show_404(); (note, means you do it manually by some reason) it will show same page .
[eluser]Burak Erdem[/eluser]
[quote author="victorche" date="1296407257"]Maybe we should wait for some updates in the user guide ... As I can see, it is still not complete and maybe it is a work in progress. There are even some missing parts, like: http://ellislab.com/codeigniter/user-gui...lding.html[/quote] Scaffolding has been removed as of version 2, look at the change log http://ellislab.com/codeigniter/user-gui...gelog.html
[eluser]boxyee[/eluser]
From what I understand, there is a new $route[‘404_override’] config item, which lets you set the controller to redirect to when a controller isn't found. Eg. If $route[‘404_override’] is set to 'custom-error', then when you browse to domain.com/invalid-controller, the custom-error controller is loaded. You could use this in some sort of CMS to load a page dependant on the URL or just as your own errors controller.
[eluser]skunkbad[/eluser]
This is the way I've been handling errors. Works for more than just 404: MY_Exceptions: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); errorpage controller: Code: <?php errorpage view: Code: <div id="single-column"> I'd love to know if there is a better/easier way to handle ALL errors!
[eluser]victorche[/eluser]
Thanks for the info, but... why when I have a custom 404, and I am using the option to override the default 404... Then my libraries are not autoloaded. Why is this and how can I avoid it? Code: A PHP Error was encountered
[eluser]cominus[/eluser]
Victorche - here is what I did: In applications/config/routes/ approx line 42: Code: $route['404_override'] = 'errors/page_missing'; new file applications/controllers/errors.php: Code: <?php new file applications/views/page_missing.php: Code: <div id="content-1col"> The page_missing custom error page overrides the stock CI error message for 404. The only problem I have (which is located at thread http://ellislab.com/forums/viewthread/181342/ ) is the forbidden option is not working - the custom 404 page missing error page is presented there also. So, that is a start. Hope this is helpful.
[eluser]William Rufino[/eluser]
What do I do if I need to invoke show_404 ? |
Welcome Guest, Not a member yet? Register Sign In |