driver($library[, $params = NULL[, $object_name]])
Parameters: |
|
---|---|
Returns: |
CI_Loader instance (method chaining) |
Return type: |
CI_Loader |
This method is used to load driver libraries, acts very much like the library()
method.
As an example, if you would like to use sessions with CodeIgniter, the first step is to load the session driver within your controller:
$this->load->driver('session');
Once loaded, the library will be ready for use, using $this->session
.
Driver files must be stored in a subdirectory within the main “libraries” directory, or within your personal application/libraries directory. The subdirectory must match the parent class name. Read the Drivers description for details.
Additionally, multiple driver libraries can be loaded at the same time by passing an array of drivers to the load method.
$this->load->driver(array('session', 'cache'));
Setting options
The second (optional) parameter allows you to optionally pass configuration settings. You will typically pass these as an array:
$config = array( 'sess_driver' => 'cookie', 'sess_encrypt_cookie' => true, 'encryption_key' => 'mysecretkey' ); $this->load->driver('session', $config);
Config options can usually also be set via a config file. Each library is explained in detail in its own page, so please read the information regarding each one you would like to use.
Assigning a Driver to a different object name
If the third (optional) parameter is blank, the library will be assigned to an object with the same name as the parent class. For example, if the library is named Session, it will be assigned to a variable named $this->session
.
If you prefer to set your own class names you can pass its value to the third parameter:
$this->load->library('session', '', 'my_session'); // Session class is now accessed using: $this->my_session
Please login to continue.