Welcome Guest, Not a member yet? Register   Sign In
Composer breaks exisiting autoload in Codeigniter
#1

[eluser]coderego[/eluser]
I was using Codeigniter to do autoloading for some core classes using the method described here:

Code:
http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY

function __autoload($class)
{
if(strpos($class, 'CI_') !== 0)
{
  @include_once( APPPATH . 'core/'. $class . EXT );
}
}
However, once I installed composer (in order to use Eloquent), this funcitonality no longer works. Any ideas?

Thanks!
#2

[eluser]Aken[/eluser]
Replace your __autoload() function with an spl_autoload_register().
#3

[eluser]Adrian Walls[/eluser]
I had the very same issue the other day. Remove the lines relating to autoload above and add the following to your composer.json file:

Code:
"autoload": {
  "classmap": ["application/core"]
},

Also, don't forget to add the composer autoload file to your CI bootstrap file.
#4

[eluser]coderego[/eluser]
Adrian Walls,

That should work....but it doesn't. is there any pathing considerations maybe?

composer.json is in the project root.
application is a folder in the root.


{

"autoload": {
"classmap": ["application/core"]
},

"require": {
"php": ">=5.3.0",
"illuminate/database": "*"
}


}
#5

[eluser]coderego[/eluser]
Adrian Walls,

That should work....but it doesn't. is there any pathing considerations maybe?

composer.json is in the project root.
application is a folder in the root.


Code:
{

    "autoload": {
        "classmap": ["application/core"]
    },

    "require": {
        "php": ">=5.3.0",
        "illuminate/database": "*"
    }


}
#6

[eluser]Adrian Walls[/eluser]
There shouldn't be. My composer.json file is at the web root level and so is the CI application folder.

What exactly is happening when you do this? How are you including the composer autoload.php file?

I've added the following to index.php:

Code:
/*
* --------------------------------------------------------------------
* COMPOSER AUTOLOAD
* --------------------------------------------------------------------
*/
include_once './vendor/autoload.php';

just before:

Code:
/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
* --------------------------------------------------------------------
*
* And away we go...
*
*/
require_once BASEPATH.'core/CodeIgniter.php';




Theme © iAndrew 2016 - Forum software by © MyBB