How to load a view for the error page? |
[eluser]Randy Casburn[/eluser]
@Aquillyne -- If you're using PHP v5 it may be a perfect opportunity for you to explore PHP's exception processing features. Just a thought... Ramdy
[eluser]Aquillyne[/eluser]
[quote author="Randy Casburn" date="1216591782"]@Aquillyne -- If you're using PHP v5 it may be a perfect opportunity for you to explore PHP's exception processing features. Just a thought... Ramdy[/quote] I am indeed using PHP 5, but I'd like to keep my whole application as compatible as possible. Thanks for the tip though!
[eluser]Aquillyne[/eluser]
I've managed to get it working. You extend the Exceptions class as follows: MY_Exceptions Code: class MY_Exceptions extends CI_Exceptions { Then you just need an error controller ("error"), which captures the session flashdata, and feeds it into an error view. Note that I've got the sessions class set to autoload in my autoload.php config file.
[eluser]Aquillyne[/eluser]
Ack; more problems. The above code seems to work on anything but a 404 error. For this I get the error: "Call to undefined function get_instance()". Why is this? As a side-note, I also get an extremely strange error for PHP errors. If my error message includes the filename I get an infinite redirection loop. If the message doesn't include the filename is works perfectly. What on earth?
[eluser]Pascal Kriete[/eluser]
Most of the 404 errors get called before the base classes are loaded, so get_instance isn't defined yet. Also, the super object won't be instantiated yet. That's also the reason why I resorted to php sessions for my implementation.
[eluser]Aquillyne[/eluser]
Okay the fixed code that even works on 404's. I've used CI sessions where possible, but only in the case where CI isn't yet instantiated (404 errors), it resorts to native PHP sessions. MY_Exceptions.php Code: class MY_Exceptions extends CI_Exceptions { This also requires something special in the error controller. error.php in controllers folder Code: class Error extends Controller { |
Welcome Guest, Not a member yet? Register Sign In |