I’m trying to load the Google calendar API which comes in PHP, but firstly to load the API, I need to pass the apiClient class instance to another class, I’m having no success at this since I’m using Codeigniter to load the apiClient library, but it fails to load the second class.
What I’ve done:
$this->load->library('google/apiClient', NULL, 'apiClient');
echo gettype($this->apiClient); // object
// This class needs the `apiClient` class to be passed to this, but fails
$this->load->library('google/contrib/apiCalendarService', $this->apiClient);
The error that gets thrown is this:
Argument 1 passed to apiCalendarService::__construct() must be an instance of apiClient, none given
However, if I do this:
$this->load->library('google/contrib/apiCalendarService', array($this->apiClient));
It will throw this error (passed the $this->apiClient in an array):
Argument 1 passed to apiCalendarService::__construct() must be an instance of apiClient, array given
What is the problem here? How can I specifically pass the apiClient to the apiCalendarService class?
The problem here is that CodeIgniter expects an array as the first parameter passed to all libraries, so not all classes fit in by default as CI libraries (particularly, ones that expect constructor parameters).
I see two options here:
includethe class and instantiatenew apiCalendarService($this->apiClient)Option #1 is two lines of code, by the way.