Welcome Guest, Not a member yet? Register   Sign In
No get_instance() in error_404.php?
#1

[eluser]Anny FM[/eluser]
Hi,

First encountered CodeIgniter over a year ago and have become pretty comfortable with it since, but for the first time I am actually working on the interface (as opposed to working on systems, while colleagues developed the front-end).

I want to use the standard header and footer for the rest of the site in error pages, in this manner:

Code:
<?php $ci = get_instance(); $ci->load->view( 'template/header', array( 'title' => 'Page not found' ); ?>

<!-- Error page text goes here -->

<?php $ci->load->view( 'template/footer' ); ?>

However, it seems that get_instance() is an undefined function, which presumably means that the 404 is detected even before CodeIgniter is loaded. I don't want to duplicate the header and footer manually for each error page as that becomes harder to manage, especially considering the template files utilise Helper functionality.

How can I work around this? Would a manual include() be the easiest way, with modifications to the separate template files to use plain HTML rather than generator functions? Or can I change error handling behaviour, preferably without modifying CI itself, to make get_instance() available?

Thanks
#2

[eluser]Phil Sturgeon[/eluser]
404 happens too early on for that to work. I use a redirect to send the user to a more interesting 404 page, but the are probably better solutions around.
#3

[eluser]Anny FM[/eluser]
I thought that might be the case, but not allowing access to dynamic features in CodeIgniter on a 404 seems like a huge oversight. I guess I'll just use redirection for now. Thanks.
#4

[eluser]CroNiX[/eluser]
search around, there are solutions better than a redirect Smile
#5

[eluser]Aken[/eluser]
Yeah, this has been brought to the CI people's attention many times. As of right now, there's a perfectly logical explanation as to why it works that way, and I don't know if it's something they actually intend to work around. But they know about it. Smile
#6

[eluser]Anny FM[/eluser]
[quote author="CroNiX" date="1259369422"]search around, there are solutions better than a redirect Smile[/quote]

Without meaning to sound ungrateful, would you care to enlighten me as to these solutions?
#7

[eluser]garymardell[/eluser]
Untested by me, and not made by me but heres something i found.

http://maestric.com/doc/php/codeigniter_404
#8

[eluser]CroNiX[/eluser]
[quote author="Anny FM" date="1259376024"][quote author="CroNiX" date="1259369422"]search around, there are solutions better than a redirect Smile[/quote]

Without meaning to sound ungrateful, would you care to enlighten me as to these solutions?[/quote]
This is the best Ive found:
http://maestric.com/doc/php/codeigniter_404

Its a true dynamic 404 solution that gives you access to all of CI's goodness. It works for every case Ive thrown at it.

Just remember in the error.php file to include a proper 404 header
Code:
header("HTTP/1.1 404 Not Found");
before sending the view.

Hope it helps.
#9

[eluser]Anny FM[/eluser]
Thanks both, I'll check it out tomorrow. Tonight is beer drinking night so it's probably ill advised to try to make this work right now!
#10

[eluser]CroNiX[/eluser]
[quote author="Anny FM" date="1259379602"]Tonight is beer drinking night so it's probably ill advised to try to make this work right now![/quote]
But thats the best time Tongue




Theme © iAndrew 2016 - Forum software by © MyBB