Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ############ |
| 2 | Loader Class |
| 3 | ############ |
| 4 | |
| 5 | Loader, as the name suggests, is used to load elements. These elements |
| 6 | can be libraries (classes) :doc:`View files <../general/views>`, |
dchill42 | 3169f26 | 2012-08-11 20:12:05 -0400 | [diff] [blame] | 7 | :doc:`Drivers <../general/drivers>`, |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 8 | :doc:`Helpers <../general/helpers>`, |
| 9 | :doc:`Models <../general/models>`, or your own files. |
| 10 | |
| 11 | .. note:: This class is initialized automatically by the system so there |
| 12 | is no need to do it manually. |
| 13 | |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 14 | .. contents:: |
| 15 | :local: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 16 | |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 17 | .. raw:: html |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 18 | |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 19 | <div class="custom-index container"></div> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 20 | |
James L Parry | 08191be | 2014-12-20 02:37:13 -0800 | [diff] [blame] | 21 | ********************** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 22 | Application "Packages" |
James L Parry | 08191be | 2014-12-20 02:37:13 -0800 | [diff] [blame] | 23 | ********************** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 24 | |
| 25 | An application package allows for the easy distribution of complete sets |
| 26 | of resources in a single directory, complete with its own libraries, |
| 27 | models, helpers, config, and language files. It is recommended that |
Andrey Andreev | c26d34f | 2013-01-28 21:46:08 +0200 | [diff] [blame] | 28 | these packages be placed in the application/third_party directory. Below |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 29 | is a sample map of an package directory. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 30 | |
| 31 | The following is an example of a directory for an application package |
| 32 | named "Foo Bar". |
| 33 | |
| 34 | :: |
| 35 | |
Derek Jones | 36be969 | 2011-10-05 15:52:41 -0500 | [diff] [blame] | 36 | /application/third_party/foo_bar |
| 37 | |
| 38 | config/ |
| 39 | helpers/ |
| 40 | language/ |
| 41 | libraries/ |
| 42 | models/ |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 43 | |
| 44 | Whatever the purpose of the "Foo Bar" application package, it has its |
| 45 | own config files, helpers, language files, libraries, and models. To use |
| 46 | these resources in your controllers, you first need to tell the Loader |
| 47 | that you are going to be loading resources from a package, by adding the |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 48 | package path via the ``add_package_path()`` method. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 49 | |
| 50 | Package view files |
| 51 | ------------------ |
| 52 | |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 53 | By Default, package view files paths are set when ``add_package_path()`` |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 54 | is called. View paths are looped through, and once a match is |
| 55 | encountered that view is loaded. |
| 56 | |
| 57 | In this instance, it is possible for view naming collisions within |
| 58 | packages to occur, and possibly the incorrect package being loaded. To |
| 59 | ensure against this, set an optional second parameter of FALSE when |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 60 | calling ``add_package_path()``. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 61 | |
| 62 | :: |
| 63 | |
| 64 | $this->load->add_package_path(APPPATH.'my_app', FALSE); |
| 65 | $this->load->view('my_app_index'); // Loads |
| 66 | $this->load->view('welcome_message'); // Will not load the default welcome_message b/c the second param to add_package_path is FALSE |
| 67 | |
| 68 | // Reset things |
| 69 | $this->load->remove_package_path(APPPATH.'my_app'); |
| 70 | |
| 71 | // Again without the second parameter: |
W. Kristianto | a5e329f | 2012-09-23 22:34:18 +0700 | [diff] [blame] | 72 | $this->load->add_package_path(APPPATH.'my_app'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 73 | $this->load->view('my_app_index'); // Loads |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 74 | $this->load->view('welcome_message'); // Loads |
| 75 | |
| 76 | *************** |
| 77 | Class Reference |
| 78 | *************** |
| 79 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 80 | .. php:class:: CI_Loader |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 81 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 82 | .. php:method:: library($library[, $params = NULL[, $object_name = NULL]]) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 83 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 84 | :param mixed $library: Library name as a string or an array with multiple libraries |
| 85 | :param array $params: Optional array of parameters to pass to the loaded library's constructor |
| 86 | :param string $object_name: Optional object name to assign the library to |
| 87 | :returns: CI_Loader instance (method chaining) |
| 88 | :rtype: CI_Loader |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 89 | |
| 90 | This method is used to load core classes. |
| 91 | |
| 92 | .. note:: We use the terms "class" and "library" interchangeably. |
| 93 | |
| 94 | For example, if you would like to send email with CodeIgniter, the first |
| 95 | step is to load the email class within your controller:: |
| 96 | |
| 97 | $this->load->library('email'); |
| 98 | |
| 99 | Once loaded, the library will be ready for use, using ``$this->email``. |
| 100 | |
| 101 | Library files can be stored in subdirectories within the main |
| 102 | "libraries" directory, or within your personal *application/libraries* |
| 103 | directory. To load a file located in a subdirectory, simply include the |
| 104 | path, relative to the "libraries" directory. For example, if you have |
| 105 | file located at:: |
| 106 | |
| 107 | libraries/flavors/Chocolate.php |
| 108 | |
| 109 | You will load it using:: |
| 110 | |
| 111 | $this->load->library('flavors/chocolate'); |
| 112 | |
| 113 | You may nest the file in as many subdirectories as you want. |
| 114 | |
| 115 | Additionally, multiple libraries can be loaded at the same time by |
| 116 | passing an array of libraries to the load method. |
| 117 | :: |
| 118 | |
| 119 | $this->load->library(array('email', 'table')); |
| 120 | |
Connor Tumbleson | 75b3fb2 | 2014-01-11 06:58:43 -0600 | [diff] [blame] | 121 | **Setting options** |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 122 | |
| 123 | The second (optional) parameter allows you to optionally pass |
| 124 | configuration setting. You will typically pass these as an array:: |
| 125 | |
| 126 | $config = array ( |
| 127 | 'mailtype' => 'html', |
Andrey Andreev | 954c4aa | 2017-07-21 11:51:37 +0300 | [diff] [blame] | 128 | 'charset' => 'utf-8', |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 129 | 'priority' => '1' |
| 130 | ); |
| 131 | |
| 132 | $this->load->library('email', $config); |
| 133 | |
| 134 | Config options can usually also be set via a config file. Each library |
| 135 | is explained in detail in its own page, so please read the information |
| 136 | regarding each one you would like to use. |
| 137 | |
| 138 | Please take note, when multiple libraries are supplied in an array for |
| 139 | the first parameter, each will receive the same parameter information. |
| 140 | |
Connor Tumbleson | 75b3fb2 | 2014-01-11 06:58:43 -0600 | [diff] [blame] | 141 | **Assigning a Library to a different object name** |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 142 | |
| 143 | If the third (optional) parameter is blank, the library will usually be |
| 144 | assigned to an object with the same name as the library. For example, if |
| 145 | the library is named Calendar, it will be assigned to a variable named |
| 146 | ``$this->calendar``. |
| 147 | |
| 148 | If you prefer to set your own class names you can pass its value to the |
| 149 | third parameter:: |
| 150 | |
| 151 | $this->load->library('calendar', NULL, 'my_calendar'); |
| 152 | |
| 153 | // Calendar class is now accessed using: |
| 154 | $this->my_calendar |
| 155 | |
| 156 | Please take note, when multiple libraries are supplied in an array for |
| 157 | the first parameter, this parameter is discarded. |
| 158 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 159 | .. php:method:: driver($library[, $params = NULL[, $object_name]]) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 160 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 161 | :param mixed $library: Library name as a string or an array with multiple libraries |
| 162 | :param array $params: Optional array of parameters to pass to the loaded library's constructor |
| 163 | :param string $object_name: Optional object name to assign the library to |
| 164 | :returns: CI_Loader instance (method chaining) |
| 165 | :rtype: CI_Loader |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 166 | |
| 167 | This method is used to load driver libraries, acts very much like the |
| 168 | ``library()`` method. |
| 169 | |
| 170 | As an example, if you would like to use sessions with CodeIgniter, the first |
| 171 | step is to load the session driver within your controller:: |
| 172 | |
| 173 | $this->load->driver('session'); |
| 174 | |
| 175 | Once loaded, the library will be ready for use, using ``$this->session``. |
| 176 | |
| 177 | Driver files must be stored in a subdirectory within the main |
| 178 | "libraries" directory, or within your personal *application/libraries* |
| 179 | directory. The subdirectory must match the parent class name. Read the |
| 180 | :doc:`Drivers <../general/drivers>` description for details. |
| 181 | |
| 182 | Additionally, multiple driver libraries can be loaded at the same time by |
| 183 | passing an array of drivers to the load method. |
| 184 | :: |
| 185 | |
| 186 | $this->load->driver(array('session', 'cache')); |
| 187 | |
Connor Tumbleson | 75b3fb2 | 2014-01-11 06:58:43 -0600 | [diff] [blame] | 188 | **Setting options** |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 189 | |
| 190 | The second (optional) parameter allows you to optionally pass |
| 191 | configuration settings. You will typically pass these as an array:: |
| 192 | |
| 193 | $config = array( |
| 194 | 'sess_driver' => 'cookie', |
| 195 | 'sess_encrypt_cookie' => true, |
| 196 | 'encryption_key' => 'mysecretkey' |
| 197 | ); |
| 198 | |
| 199 | $this->load->driver('session', $config); |
| 200 | |
| 201 | Config options can usually also be set via a config file. Each library |
| 202 | is explained in detail in its own page, so please read the information |
| 203 | regarding each one you would like to use. |
| 204 | |
Connor Tumbleson | 75b3fb2 | 2014-01-11 06:58:43 -0600 | [diff] [blame] | 205 | **Assigning a Driver to a different object name** |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 206 | |
| 207 | If the third (optional) parameter is blank, the library will be assigned |
| 208 | to an object with the same name as the parent class. For example, if |
| 209 | the library is named Session, it will be assigned to a variable named |
| 210 | ``$this->session``. |
| 211 | |
| 212 | If you prefer to set your own class names you can pass its value to the |
| 213 | third parameter:: |
| 214 | |
| 215 | $this->load->library('session', '', 'my_session'); |
| 216 | |
| 217 | // Session class is now accessed using: |
| 218 | $this->my_session |
| 219 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 220 | .. php:method:: view($view[, $vars = array()[, return = FALSE]]) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 221 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 222 | :param string $view: View name |
| 223 | :param array $vars: An associative array of variables |
| 224 | :param bool $return: Whether to return the loaded view |
| 225 | :returns: View content string if $return is set to TRUE, otherwise CI_Loader instance (method chaining) |
| 226 | :rtype: mixed |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 227 | |
| 228 | This method is used to load your View files. If you haven't read the |
| 229 | :doc:`Views <../general/views>` section of the user guide it is |
| 230 | recommended that you do since it shows you how this method is |
| 231 | typically used. |
| 232 | |
| 233 | The first parameter is required. It is the name of the view file you |
| 234 | would like to load. |
| 235 | |
| 236 | .. note:: The .php file extension does not need to be specified unless |
| 237 | you use something other than .php. |
| 238 | |
| 239 | The second **optional** parameter can take an associative array or an |
| 240 | object as input, which it runs through the PHP |
Master Yoda | bd2a7e4 | 2015-03-25 02:36:31 -0700 | [diff] [blame] | 241 | `extract() <http://php.net/extract>`_ function to convert to variables |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 242 | that can be used in your view files. Again, read the |
| 243 | :doc:`Views <../general/views>` page to learn how this might be useful. |
| 244 | |
| 245 | The third **optional** parameter lets you change the behavior of the |
| 246 | method so that it returns data as a string rather than sending it to |
| 247 | your browser. This can be useful if you want to process the data in some |
| 248 | way. If you set the parameter to TRUE (boolean) it will return data. The |
| 249 | default behavior is FALSE, which sends it to your browser. Remember to |
| 250 | assign it to a variable if you want the data returned:: |
| 251 | |
| 252 | $string = $this->load->view('myfile', '', TRUE); |
| 253 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 254 | .. php:method:: vars($vars[, $val = '']) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 255 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 256 | :param mixed $vars: An array of variables or a single variable name |
| 257 | :param mixed $val: Optional variable value |
| 258 | :returns: CI_Loader instance (method chaining) |
| 259 | :rtype: CI_Loader |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 260 | |
| 261 | This method takes an associative array as input and generates |
Master Yoda | bd2a7e4 | 2015-03-25 02:36:31 -0700 | [diff] [blame] | 262 | variables using the PHP `extract() <http://php.net/extract>`_ |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 263 | function. This method produces the same result as using the second |
| 264 | parameter of the ``$this->load->view()`` method above. The reason you |
| 265 | might want to use this method independently is if you would like to |
| 266 | set some global variables in the constructor of your controller and have |
| 267 | them become available in any view file loaded from any method. You can |
| 268 | have multiple calls to this method. The data get cached and merged |
| 269 | into one array for conversion to variables. |
| 270 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 271 | .. php:method:: get_var($key) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 272 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 273 | :param string $key: Variable name key |
| 274 | :returns: Value if key is found, NULL if not |
| 275 | :rtype: mixed |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 276 | |
| 277 | This method checks the associative array of variables available to |
| 278 | your views. This is useful if for any reason a var is set in a library |
| 279 | or another controller method using ``$this->load->vars()``. |
| 280 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 281 | .. php:method:: get_vars() |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 282 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 283 | :returns: An array of all assigned view variables |
| 284 | :rtype: array |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 285 | |
| 286 | This method retrieves all variables available to your views. |
| 287 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 288 | .. php:method:: clear_vars() |
Andrey Andreev | ea801ab | 2014-01-20 15:03:43 +0200 | [diff] [blame] | 289 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 290 | :returns: CI_Loader instance (method chaining) |
| 291 | :rtype: CI_Loader |
Andrey Andreev | ea801ab | 2014-01-20 15:03:43 +0200 | [diff] [blame] | 292 | |
| 293 | Clears cached view variables. |
| 294 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 295 | .. php:method:: model($model[, $name = ''[, $db_conn = FALSE]]) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 296 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 297 | :param mixed $model: Model name or an array containing multiple models |
| 298 | :param string $name: Optional object name to assign the model to |
| 299 | :param string $db_conn: Optional database configuration group to load |
| 300 | :returns: CI_Loader instance (method chaining) |
| 301 | :rtype: CI_Loader |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 302 | |
| 303 | :: |
| 304 | |
| 305 | $this->load->model('model_name'); |
| 306 | |
| 307 | |
| 308 | If your model is located in a subdirectory, include the relative path |
| 309 | from your models directory. For example, if you have a model located at |
Andrey Andreev | ea801ab | 2014-01-20 15:03:43 +0200 | [diff] [blame] | 310 | *application/models/blog/Queries.php* you'll load it using:: |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 311 | |
| 312 | $this->load->model('blog/queries'); |
| 313 | |
| 314 | If you would like your model assigned to a different object name you can |
| 315 | specify it via the second parameter of the loading method:: |
| 316 | |
| 317 | $this->load->model('model_name', 'fubar'); |
| 318 | $this->fubar->method(); |
| 319 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 320 | .. php:method:: database([$params = ''[, $return = FALSE[, $query_builder = NULL]]]) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 321 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 322 | :param mixed $params: Database group name or configuration options |
| 323 | :param bool $return: Whether to return the loaded database object |
| 324 | :param bool $query_builder: Whether to load the Query Builder |
| 325 | :returns: Loaded CI_DB instance or FALSE on failure if $return is set to TRUE, otherwise CI_Loader instance (method chaining) |
| 326 | :rtype: mixed |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 327 | |
| 328 | This method lets you load the database class. The two parameters are |
| 329 | **optional**. Please see the :doc:`database <../database/index>` |
| 330 | section for more info. |
| 331 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 332 | .. php:method:: dbforge([$db = NULL[, $return = FALSE]]) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 333 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 334 | :param object $db: Database object |
| 335 | :param bool $return: Whether to return the Database Forge instance |
| 336 | :returns: Loaded CI_DB_forge instance if $return is set to TRUE, otherwise CI_Loader instance (method chaining) |
| 337 | :rtype: mixed |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 338 | |
| 339 | Loads the :doc:`Database Forge <../database/forge>` class, please refer |
| 340 | to that manual for more info. |
| 341 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 342 | .. php:method:: dbutil([$db = NULL[, $return = FALSE]]) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 343 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 344 | :param object $db: Database object |
| 345 | :param bool $return: Whether to return the Database Utilities instance |
| 346 | :returns: Loaded CI_DB_utility instance if $return is set to TRUE, otherwise CI_Loader instance (method chaining) |
| 347 | :rtype: mixed |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 348 | |
| 349 | Loads the :doc:`Database Utilities <../database/utilities>` class, please |
| 350 | refer to that manual for more info. |
| 351 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 352 | .. php:method:: helper($helpers) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 353 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 354 | :param mixed $helpers: Helper name as a string or an array containing multiple helpers |
| 355 | :returns: CI_Loader instance (method chaining) |
| 356 | :rtype: CI_Loader |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 357 | |
| 358 | This method loads helper files, where file_name is the name of the |
| 359 | file, without the _helper.php extension. |
| 360 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 361 | .. php:method:: file($path[, $return = FALSE]) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 362 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 363 | :param string $path: File path |
| 364 | :param bool $return: Whether to return the loaded file |
| 365 | :returns: File contents if $return is set to TRUE, otherwise CI_Loader instance (method chaining) |
| 366 | :rtype: mixed |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 367 | |
| 368 | This is a generic file loading method. Supply the filepath and name in |
| 369 | the first parameter and it will open and read the file. By default the |
| 370 | data is sent to your browser, just like a View file, but if you set the |
| 371 | second parameter to boolean TRUE it will instead return the data as a |
| 372 | string. |
| 373 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 374 | .. php:method:: language($files[, $lang = '']) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 375 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 376 | :param mixed $files: Language file name or an array of multiple language files |
| 377 | :param string $lang: Language name |
| 378 | :returns: CI_Loader instance (method chaining) |
| 379 | :rtype: CI_Loader |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 380 | |
| 381 | This method is an alias of the :doc:`language loading |
| 382 | method <language>`: ``$this->lang->load()``. |
| 383 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 384 | .. php:method:: config($file[, $use_sections = FALSE[, $fail_gracefully = FALSE]]) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 385 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 386 | :param string $file: Configuration file name |
| 387 | :param bool $use_sections: Whether configuration values should be loaded into their own section |
| 388 | :param bool $fail_gracefully: Whether to just return FALSE in case of failure |
| 389 | :returns: TRUE on success, FALSE on failure |
| 390 | :rtype: bool |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 391 | |
| 392 | This method is an alias of the :doc:`config file loading |
| 393 | method <config>`: ``$this->config->load()`` |
| 394 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 395 | .. php:method:: is_loaded($class) |
Andrey Andreev | ea801ab | 2014-01-20 15:03:43 +0200 | [diff] [blame] | 396 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 397 | :param string $class: Class name |
| 398 | :returns: Singleton property name if found, FALSE if not |
| 399 | :rtype: mixed |
Andrey Andreev | ea801ab | 2014-01-20 15:03:43 +0200 | [diff] [blame] | 400 | |
| 401 | Allows you to check if a class has already been loaded or not. |
| 402 | |
| 403 | .. note:: The word "class" here refers to libraries and drivers. |
| 404 | |
| 405 | If the requested class has been loaded, the method returns its assigned |
| 406 | name in the CI Super-object and FALSE if it's not:: |
| 407 | |
| 408 | $this->load->library('form_validation'); |
| 409 | $this->load->is_loaded('Form_validation'); // returns 'form_validation' |
| 410 | |
| 411 | $this->load->is_loaded('Nonexistent_library'); // returns FALSE |
| 412 | |
| 413 | .. important:: If you have more than one instance of a class (assigned to |
| 414 | different properties), then the first one will be returned. |
| 415 | |
| 416 | :: |
| 417 | |
| 418 | $this->load->library('form_validation', $config, 'fv'); |
| 419 | $this->load->library('form_validation'); |
| 420 | |
| 421 | $this->load->is_loaded('Form_validation'); // returns 'fv' |
| 422 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 423 | .. php:method:: add_package_path($path[, $view_cascade = TRUE]) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 424 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 425 | :param string $path: Path to add |
| 426 | :param bool $view_cascade: Whether to use cascading views |
| 427 | :returns: CI_Loader instance (method chaining) |
| 428 | :rtype: CI_Loader |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 429 | |
| 430 | Adding a package path instructs the Loader class to prepend a given path |
| 431 | for subsequent requests for resources. As an example, the "Foo Bar" |
| 432 | application package above has a library named Foo_bar.php. In our |
| 433 | controller, we'd do the following:: |
| 434 | |
Andrey Andreev | 0c9d080 | 2014-01-07 13:39:23 +0200 | [diff] [blame] | 435 | $this->load->add_package_path(APPPATH.'third_party/foo_bar/') |
| 436 | ->library('foo_bar'); |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 437 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 438 | .. php:method:: remove_package_path([$path = '']) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 439 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 440 | :param string $path: Path to remove |
| 441 | :returns: CI_Loader instance (method chaining) |
| 442 | :rtype: CI_Loader |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 443 | |
| 444 | When your controller is finished using resources from an application |
| 445 | package, and particularly if you have other application packages you |
| 446 | want to work with, you may wish to remove the package path so the Loader |
| 447 | no longer looks in that directory for resources. To remove the last path |
| 448 | added, simply call the method with no parameters. |
| 449 | |
| 450 | Or to remove a specific package path, specify the same path previously |
| 451 | given to ``add_package_path()`` for a package.:: |
| 452 | |
| 453 | $this->load->remove_package_path(APPPATH.'third_party/foo_bar/'); |
| 454 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 455 | .. php:method:: get_package_paths([$include_base = TRUE]) |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 456 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 457 | :param bool $include_base: Whether to include BASEPATH |
| 458 | :returns: An array of package paths |
| 459 | :rtype: array |
Andrey Andreev | 0556396 | 2014-01-06 12:28:59 +0200 | [diff] [blame] | 460 | |
| 461 | Returns all currently available package paths. |