Welcome Guest, Not a member yet? Register   Sign In
strange routing error? Autoload not being called on some 404's.
#1

[eluser]gRoberts[/eluser]
Hi everyone,

I've setup all of my error_* documents that include my site header and footer.

The header and footer uses the base_url() call, so I have set it up to autoload the URL helper.

When I go to an url where the controller exists but the action doesn't, all works fine, the error page shows.

If I go to a an url where the controller does not exist, I get "Call to undefined function base_url()"

Any idea's? I tried using get_instance and then loading the helper manually in the header and it fails on "Call to undefined function get_instance()"

Any idea's?

Cheers

Gav
#2

[eluser]Bart v B[/eluser]
maybe some code should be nice. Wink
Then it's easyer to help.
#3

[eluser]gRoberts[/eluser]
autoload.php
Code:
$autoload['helper'] = array('url');

error_*.php
Code:
<? include(APPPATH . '/views/common/header.php'); ?>
                <div class="item">
                    <h2>&lt;?= $heading; ?&gt;</h2>
                    <p>&lt;?= $message; ?&gt;</p>
                </div>
&lt;? include(APPPATH . '/views/common/footer.php'); ?&gt;

header.php
Code:
<img src="&lt;?= base_url(); ?&gt;assets/images/logo.png" alt="Company name" title="Company name" />

Theres not really much to see.

Cheers
#4

[eluser]gRoberts[/eluser]
Might be a bug. I've been able to replicate it on another site.

Error output:

Code:
DEBUG - 2010-04-22 07:07:32 --&gt; Config Class Initialized
DEBUG - 2010-04-22 07:07:32 --&gt; Hooks Class Initialized
DEBUG - 2010-04-22 07:07:32 --&gt; URI Class Initialized
ERROR - 2010-04-22 07:07:32 --&gt; 404 Page Not Found --&gt; activities <-- controller does not exist
DEBUG - 2010-04-22 07:07:33 --&gt; Config Class Initialized
DEBUG - 2010-04-22 07:07:33 --&gt; Hooks Class Initialized
DEBUG - 2010-04-22 07:07:33 --&gt; URI Class Initialized
DEBUG - 2010-04-22 07:07:47 --&gt; Config Class Initialized
DEBUG - 2010-04-22 07:07:47 --&gt; Hooks Class Initialized
DEBUG - 2010-04-22 07:07:47 --&gt; URI Class Initialized
DEBUG - 2010-04-22 07:07:47 --&gt; Router Class Initialized
DEBUG - 2010-04-22 07:07:47 --&gt; Output Class Initialized
DEBUG - 2010-04-22 07:07:47 --&gt; Input Class Initialized
DEBUG - 2010-04-22 07:07:47 --&gt; Global POST and COOKIE data sanitized
DEBUG - 2010-04-22 07:07:47 --&gt; Language Class Initialized
DEBUG - 2010-04-22 07:07:47 --&gt; Loader Class Initialized
DEBUG - 2010-04-22 07:07:47 --&gt; Helper loaded: url_helper
DEBUG - 2010-04-22 07:07:47 --&gt; Controller Class Initialized
ERROR - 2010-04-22 07:07:47 --&gt; 404 Page Not Found --&gt; projects/vi12341234 <-- controller exists
#5

[eluser]gRoberts[/eluser]
Anyone got any idea's before I make this a bug?
#6

[eluser]danmontgomery[/eluser]
Neither of these are bugs...

The 404 page is thrown when the router class is loaded, on line 99 of CodeIgniter.php. get_instance() is defined when Base4.php or Base5.php are included (line 140 or 144 of CodeIgniter.php) and autoload is run when the Controller class is declared (line 148 of CodeIgniter.php).

As for the log with a seemingly non-functioning router, there is either a problem with your controller or routing that is causing the page not to be found.
#7

[eluser]gRoberts[/eluser]
The site is a vanilla setup of CI 1.7.2.

No changes to the route.php, no MY_router.php, etc.

If it's not an error. Are you/CI suggesting we all use absolute url's on our error pages?

Thanks for your help!
#8

[eluser]danmontgomery[/eluser]
Whether you use absolute or relative paths have nothing to do with whether or not you use the url helper or the CI super object...

I'm saying if the controller doesn't exist execution is halted before you have access to these things. If you need to use CI functionality in the 404 page, I'd suggest you use _remap or a catch-all route at the bottom of routes.php to redirect any 404s to your own 404 controller.
#9

[eluser]CroNiX[/eluser]
Here is a good article on a 404 controller that lets you use the CI superglobal. I use this in all of my projects so I can generate dynamic 404 pages (like getting data from the db, logging the 404 in the database, etc).
http://maestric.com/doc/php/codeigniter_404
#10

[eluser]gRoberts[/eluser]
I find it disappointing that the functionality isn't consistent.

If the functionality exists, it should work in both instances. That said, I understand that the autoloader isn't loaded until a certain point. So I would need to use absolute URL's in my header/footer.

This just makes it harder to move the site, despite the framework promoting portability.

Thanks everyone!




Theme © iAndrew 2016 - Forum software by © MyBB