CodeIgniter Forums
config.php autoload question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: config.php autoload question (/showthread.php?tid=40352)



config.php autoload question - El Forum - 04-06-2011

[eluser]LuckyFella73[/eluser]
Hi there,

I'm extending my controller like Phil suggested on his blog. For getting
that to work we have to place the "autoload - code" in our config.php

I never had a problem with that but in my actual project where I use the
old Ajax-Library (found in the CI Wiki) I get this error message in my logs:
Code:
ERROR - 2011-04-06 15:45:00 --&gt; Severity: Warning  --&gt; include_once(application/core/MY_Xajax.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory D:\xampp\htdocs\edc\admin_201\application\config\config.php 388
ERROR - 2011-04-06 15:45:00 --&gt; Severity: Warning  --&gt; include_once() [<a href='function.include'>function.include</a>]: Failed opening 'application/core/MY_Xajax.php' for inclusion (include_path='.;\xampp\php\PEAR') D:\xampp\htdocs\edc\admin_201\application\config\config.php 388

I have CI 2.0.1 installed

I just would like to know why the autoload function is looking for MY_Ajax.php in application/core ?


config.php autoload question - El Forum - 06-30-2011

[eluser]internut[/eluser]
getting the same errors...


config.php autoload question - El Forum - 06-30-2011

[eluser]InsiteFX[/eluser]
Here is the new autoloader which was updated:
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;
        }
    }
}
MY_Xajax should go into application/libraries I think.

InsiteFX


config.php autoload question - El Forum - 06-30-2011

[eluser]internut[/eluser]
I'm not using v2 but the older version.

Is this ok:

Code:
function __autoload($class)
{
if(strpos($class, 'CI_') !== 0)
{

    if (file_exists(APPPATH . 'libraries/'. $class . EXT ))  {
      @include_once( APPPATH . 'libraries/'. $class . EXT );

     }
}
}

?

Seems to be working on. Could I run into problems with this?


config.php autoload question - El Forum - 06-30-2011

[eluser]InsiteFX[/eluser]
It should work fine if your not using CI 2.0.+

InsiteFX


config.php autoload question - El Forum - 06-30-2011

[eluser]internut[/eluser]
thx @InsiteFX - seems to be working just fine.