Welcome Guest, Not a member yet? Register   Sign In
Loading core controller as well as composer libraries
#1

Hi there

Some of my site's controllers extend `core/Api_controller.php` like this:

Code:
class Basket extends Api_Controller {

Api_controller, in turn, extends `core/MY_Controller` which extends `CI_Controller`


In order to make this work I had to add the following to the bottom of my config.php:

Code:
function __autoload($class)
{
   if (strpos($class, 'CI_') !== 0)
   {
       if (file_exists($file = APPPATH . 'core/' . $class . '.php'))
       {
           include $file;
       }
       elseif (file_exists($file = APPPATH . 'libraries/' . $class . '.php'))
       {
           include $file;
       }
   }
}


This worked fine... until I wanted to load a 3rd party library. I enabled `composer_autoload` in my config.php:

Code:
$config['composer_autoload'] = '../vendor/autoload.php';

'vendor' is outside my application directory. I have verified that this autoload file is being loaded.



But now when I load one of my API controllers I get an error:

Code:
Class 'Api_Controller' not found in [absolute path]/deploy/application/controllers/api/Basket.php on line 12


I assume this is because my autoload paths are being managed by the Composer autoloader.


How can I load custom core controllers as well as using 3rd party libraries in my vendor directory?
Reply


Messages In This Thread
Loading core controller as well as composer libraries - by aderowbotham - 06-14-2018, 03:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB