blob: b64b0e75ed7325d889d66b5d15676b24918dbd0e [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001#########################
2Using CodeIgniter Drivers
3#########################
4
5Drivers are a special type of Library that has a parent class and any
6number of potential child classes. Child classes have access to the
7parent class, but not their siblings. Drivers provide an elegant syntax
8in your :doc:`controllers <controllers>` for libraries that benefit
9from or require being broken down into discrete classes.
10
Andrey Andreev16a704c2012-11-09 17:25:00 +020011Drivers are found in the *system/libraries/* directory, in their own
12sub-directory which is identically named to the parent library class.
13Also inside that directory is a subdirectory named drivers, which
14contains all of the possible child class files.
Derek Jones8ede1a22011-10-05 13:34:52 -050015
16To use a driver you will initialize it within a controller using the
Andrey Andreev16a704c2012-11-09 17:25:00 +020017following initialization method::
Derek Jones8ede1a22011-10-05 13:34:52 -050018
Andrey Andreev16a704c2012-11-09 17:25:00 +020019 $this->load->driver('class_name');
Derek Jones8ede1a22011-10-05 13:34:52 -050020
21Where class name is the name of the driver class you want to invoke. For
Andrey Andreev16a704c2012-11-09 17:25:00 +020022example, to load a driver named "Some_parent" you would do this::
Derek Jones8ede1a22011-10-05 13:34:52 -050023
24 $this->load->driver('some_parent');
25
26Methods of that class can then be invoked with::
27
28 $this->some_parent->some_method();
29
30The child classes, the drivers themselves, can then be called directly
31through the parent class, without initializing them::
32
Derek Jones9713cce2011-10-05 17:26:43 -050033 $this->some_parent->child_one->some_method();
34 $this->some_parent->child_two->another_method();
Derek Jones8ede1a22011-10-05 13:34:52 -050035
36Creating Your Own Drivers
37=========================
38
39Please read the section of the user guide that discusses how to :doc:`create
Andrey Andreev16a704c2012-11-09 17:25:00 +020040your own drivers <creating_drivers>`.