Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ######################### |
| 2 | Using CodeIgniter Drivers |
| 3 | ######################### |
| 4 | |
| 5 | Drivers are a special type of Library that has a parent class and any |
| 6 | number of potential child classes. Child classes have access to the |
| 7 | parent class, but not their siblings. Drivers provide an elegant syntax |
| 8 | in your :doc:`controllers <controllers>` for libraries that benefit |
| 9 | from or require being broken down into discrete classes. |
| 10 | |
| 11 | Drivers are found in the system/libraries folder, in their own folder |
| 12 | which is identically named to the parent library class. Also inside that |
| 13 | folder is a subfolder named drivers, which contains all of the possible |
| 14 | child class files. |
| 15 | |
| 16 | To use a driver you will initialize it within a controller using the |
| 17 | following initialization function:: |
| 18 | |
| 19 | $this->load->driver('class name'); |
| 20 | |
| 21 | Where class name is the name of the driver class you want to invoke. For |
| 22 | example, to load a driver named "Some Parent" you would do this:: |
| 23 | |
| 24 | $this->load->driver('some_parent'); |
| 25 | |
| 26 | Methods of that class can then be invoked with:: |
| 27 | |
| 28 | $this->some_parent->some_method(); |
| 29 | |
| 30 | The child classes, the drivers themselves, can then be called directly |
| 31 | through the parent class, without initializing them:: |
| 32 | |
Derek Jones | 9713cce | 2011-10-05 17:26:43 -0500 | [diff] [blame^] | 33 | $this->some_parent->child_one->some_method(); |
| 34 | $this->some_parent->child_two->another_method(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 35 | |
| 36 | Creating Your Own Drivers |
| 37 | ========================= |
| 38 | |
| 39 | Please read the section of the user guide that discusses how to :doc:`create |
| 40 | your own drivers <creating_drivers>`. |