Welcome Guest, Not a member yet? Register   Sign In
Using Sturgeon's native __autoload code, tons of errors on log file
#1

[eluser]dallen33[/eluser]
I'm using Phil Sturgeon's autoload code so I can use a "Public_Controller" and extend my controllers.

His code looks like this:

Code:
/*
| -------------------------------------------------------------------
|  Native Auto-load
| -------------------------------------------------------------------
|
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
*/
function __autoload($class)
{
    if (strpos($class, 'CI_') !== 0):
        @include_once( APPPATH . 'core/'. $class . EXT );
    endif;
}

The errors I'm getting look like this:

Code:
ERROR - 2011-06-08 13:21:20 --&gt; Severity: Warning  --&gt; include_once() [<a href='function.include'>function.include</a>]: Failed opening '/Applications/MAMP/htdocs/application/core/MY_Tasks.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5.3/lib/php') /Applications/MAMP/htdocs/application/config/config.php 371

Of course, MY_Tasks and my other libraries are kept in libraries, but because of the autoload function, I'm getting these errors. My site loads fine, but it's only when I look at the log file do I see these errors.

Any ideas?
#2

[eluser]InsiteFX[/eluser]
Thats because your using his old code! Here is the new code...
Code:
/*
| -------------------------------------------------------------------
|  Native Autoload - by Phil Sturgeon. New Version!
| -------------------------------------------------------------------
|
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
| If using HMVC you do not need this! HMVC will autoload.
|
| Place this code at the bottom of your application/config/config.php file.
*/
function __autoload($class)
{
    if (strpos($class, 'CI_') !== 0)
    {
        if (file_exists($file = APPPATH . 'core/' . $class . EXT))
        {
            include $file;
        }

        elseif (file_exists($file = APPPATH . 'libraries/' . $class . EXT))
        {
            include $file;
        }
    }
}
Also only CodeIgniter Core files go into the Core your MY_Tasks should be in libraries!

InsiteFX
#3

[eluser]DIY_Peter[/eluser]
Thanks, the symlink solution seems to work.

Still, it would be easy if they included some method in CI to put your own 'common' classes in some central location. I think many people would benefit from that.




Theme © iAndrew 2016 - Forum software by © MyBB