Reputation: 6134
I load a composer library suited for CodeIgniter called SteeveDroz\Asset
, that I can access without problem with $asset = new SteeveDroz\Asset
.
I would like to be able to load it with CodeIgniter $this->load->library('SteeveDroz\Asset')
, but I get the error message
Unable to load requested class: SteeveDroz\Asset
Is it possible to achieve what I want? If yes, how?
Upvotes: 0
Views: 443
Reputation: 6134
As mentionned Alex in his comment, it is required to make an adapter library. I created an all purpose class for that:
class ComposerAdapter
{
private $object;
public function __construct($object)
{
$this->object = $object;
}
public function __call($method, $args)
{
return call_user_func_array([$this->object, $method], $args);
}
}
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require('ComposerAdapter.php');
class Asset extends ComposerAdapter
{
public function __construct()
{
parent::__construct(new SteeveDroz\Asset());
}
}
// ...
$autoload['libraries'] = array('asset');
// ...
Upvotes: 1
Reputation:
if you are using CodeIgniter 3 you can modify application/config/config.php
and set
$config['composer_autoload'] = TRUE
or
$config['composer_autoload'] = FCPATH .'vendor/autoload.php';
this will automatically load all your composer dependencies.
Upvotes: 0