Codeigniter Drivers
ADVERTISEMENTS
- Drivers are a special kind of Library that includes a parent category and any range of potential kid categories.
- Child categories have access to the parent category, however not their siblings.
- Drivers offer a chic syntax in your controllers for libraries that like or need to be attenuated into distinct categories.
- Drivers are found in the system/libraries/ directory, in their own sub-directory which is identically named to the parent library class.
- Also within that directory could be a directory named drivers, which contains all of the possible child class files.
To use a driver you may initialize it at intervals controller exploitation the subsequent data format method:
$this->load->driver('class_name');
Where category name is that the name of the driving force category you would like to invoke.
For example, to load a driver named “Some_parent” you'd do this:
$this->load->driver('some_parent');
Methods of that category will then be invoked with:
$this->some_parent->some_method();
How to create a Codeigniter Custom Driver?
Sample driver directory and file structure layout:
/application/libraries/Driver_name
Driver_name.php
drivers
Driver_name_subclass_1.php
Driver_name_subclass_2.php
Driver_name_subclass_3.php
drivers
Driver_name_subclass_1.php
Driver_name_subclass_2.php
Driver_name_subclass_3.php
Note - so as to keep up compatibility on case-sensitive file systems, the Driver_name directory should be named within the format came back by ucfirst().
Note - The Driver library’s architecture is such that the subclasses don’t extend and therefore don’t inherit properties or methods of the main driver.