ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Composer breaks exisiting autoload in Codeigniter

April 03, 2013 10:58pm

Subscribe [2]
  • #1 / Apr 03, 2013 10:58pm

    coderego

    6 posts

    I was using Codeigniter to do autoloading for some core classes using the method described here:

    <a href="http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY">http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY</a>
    
    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 / Apr 04, 2013 1:22am

    Aken's avatar

    Aken

    2430 posts

    Replace your __autoload() function with an spl_autoload_register().

  • #3 / Apr 04, 2013 6:29am

    Adrian Walls

    59 posts

    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:

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

    Also, don’t forget to add the composer autoload file to your CI bootstrap file.

  • #4 / Apr 04, 2013 9:26am

    coderego

    6 posts

    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 / Apr 04, 2013 9:26am

    coderego

    6 posts

    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": "*"
        }
    
    
    }
  • #6 / Apr 04, 2013 10:06am

    Adrian Walls

    59 posts

    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:

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

    just before:

    /*
     * --------------------------------------------------------------------
     * LOAD THE BOOTSTRAP FILE
     * --------------------------------------------------------------------
     *
     * And away we go…
     *
     */
    require_once BASEPATH.'core/CodeIgniter.php';
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases