Loading core controller as well as composer libraries |
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) 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?
You do not need to add that to the bottom of your config file.
Just put them all in to one MY_Controller file like so. PHP Code: <?php Hope that helps. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Interesting.
So you don't necessarily need to have a class called MY_Controller inside the file MY_Controller.php? I will give that a try.
There are other ways to make this work. HERE is a page that discusses all the variations.
I am not a fan of putting more than one class in a file but it does work. I prefer using the "hooks" method as described on the linked page. You can put your autoload into config.php and fix the conflict problem with simple changes. PHP Code: function my_autoloader($class) By using spl_autoload_register() you allow multiple autoload functions to live in harmony - including the composer autoloader.
|
Welcome Guest, Not a member yet? Register Sign In |