404 How To |
[eluser]CodeIgniterNewbie[/eluser]
How do I implement my own 404? I've looked at /system/application/errors/error_404.php. Obviously, I can just change this page to anything I want. However, what if I wanted to build the page using some of my Smarty templates? How would I go about doing that? I have Smarty library auto-loaded, but when I try to access $this->mysmarty->view ... I get a "Message: Undefined property: CI_Exceptions::$mysmarty." When I am in the controllers, I have no problem calling $this->mysmarty->view. What did I miss? Also, is it even a good idea to build my 404 from Smarty templates? Any issues I should be worried about?
[eluser]TheFuzzy0ne[/eluser]
You can override the show_404() method by extending the Exceptions class. I don't think any libraries are autoloaded when a 404 error is thrown. You'd have to load them yourself. You may even find that the loader is also unavailable, so you might need to use load_class(). Don't forget, show_404 needs to be available before your controller is loaded, so I can't vouch for what libraries are/can be made available.
[eluser]CodeIgniterNewbie[/eluser]
So, how do I implement this? 1. Create a class library that extends Exception. I assume this would go in /libraries/, right? 2. Override show_404(). Will I be able to call Smarty from here? I've been exclusively using Smarty in the controllers. 3. Then what do I do with the class library I created? Do I auto load it? Do I instantiate in a controller?
[eluser]pistolPete[/eluser]
[quote author="CodeIgniterNewbie" date="1239933829"]So, how do I implement this? 1. Create a class library that extends Exception. I assume this would go in /libraries/, right? 3. Then what do I do with the class library I created? Do I auto load it? Do I instantiate in a controller?[/quote] Have a look at Extending Core Class. |
Welcome Guest, Not a member yet? Register Sign In |