admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 10 | * @license http://www.codeignitor.com/user_guide/license.html |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 15 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Loader Class |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 20 | * |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 21 | * Loads views and files |
| 22 | * |
| 23 | * @package CodeIgniter |
| 24 | * @subpackage Libraries |
| 25 | * @author Rick Ellis |
| 26 | * @category Loader |
| 27 | * @link http://www.codeigniter.com/user_guide/libraries/loader.html |
| 28 | */ |
| 29 | class CI_Loader { |
| 30 | |
admin | 34f7f2d | 2006-10-10 08:06:42 +0000 | [diff] [blame] | 31 | // All these are set automatically. Don't mess with them. |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 32 | var $_ci_ob_level; |
| 33 | var $_ci_view_path = ''; |
admin | 34f7f2d | 2006-10-10 08:06:42 +0000 | [diff] [blame] | 34 | var $_ci_is_php5 = FALSE; |
admin | 1e30398 | 2006-10-10 16:35:43 +0000 | [diff] [blame] | 35 | var $_ci_is_instance = FALSE; // Whether we should use $this or $CI =& get_instance() |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 36 | var $_ci_cached_vars = array(); |
| 37 | var $_ci_models = array(); |
| 38 | var $_ci_helpers = array(); |
| 39 | var $_ci_plugins = array(); |
| 40 | var $_ci_scripts = array(); |
| 41 | var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); |
| 42 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Constructor |
| 46 | * |
admin | 34f7f2d | 2006-10-10 08:06:42 +0000 | [diff] [blame] | 47 | * Sets the path to the view files and gets the initial output buffering level |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 48 | * |
| 49 | * @access public |
| 50 | */ |
| 51 | function CI_Loader() |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 52 | { |
admin | 34f7f2d | 2006-10-10 08:06:42 +0000 | [diff] [blame] | 53 | $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 54 | $this->_ci_view_path = APPPATH.'views/'; |
| 55 | $this->_ci_ob_level = ob_get_level(); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 56 | |
| 57 | log_message('debug', "Loader Class Initialized"); |
| 58 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 59 | |
| 60 | // -------------------------------------------------------------------- |
| 61 | |
| 62 | /** |
| 63 | * Class Loader |
| 64 | * |
| 65 | * This function lets users load and instantiate classes. |
| 66 | * It is designed to be called from a user's app controllers. |
| 67 | * |
| 68 | * @access public |
| 69 | * @param string the name of the class |
admin | 80b2bd9 | 2006-10-12 18:30:36 +0000 | [diff] [blame] | 70 | * @param mixed the optional parameters |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 71 | * @return void |
| 72 | */ |
admin | 5a14ea1 | 2006-10-12 20:42:55 +0000 | [diff] [blame] | 73 | function library($class, $params = NULL) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 74 | { |
| 75 | if ($class == '') |
| 76 | return; |
| 77 | |
admin | 80b2bd9 | 2006-10-12 18:30:36 +0000 | [diff] [blame] | 78 | $this->_ci_load_class($class, $params); |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 79 | $this->_ci_assign_to_models(); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 80 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 81 | |
| 82 | // -------------------------------------------------------------------- |
| 83 | |
| 84 | /** |
| 85 | * Model Loader |
| 86 | * |
| 87 | * This function lets users load and instantiate models. |
| 88 | * |
| 89 | * @access public |
| 90 | * @param string the name of the class |
| 91 | * @param mixed any initialization parameters |
| 92 | * @return void |
| 93 | */ |
| 94 | function model($model, $name = '', $db_conn = FALSE) |
| 95 | { |
| 96 | if ($model == '') |
| 97 | return; |
| 98 | |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 99 | // Is the model in a sub-folder? If so, parse out the filename and path. |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 100 | if (strpos($model, '/') === FALSE) |
| 101 | { |
| 102 | $path = ''; |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | $x = explode('/', $model); |
| 107 | $model = end($x); |
| 108 | unset($x[count($x)-1]); |
| 109 | $path = implode('/', $x).'/'; |
| 110 | } |
| 111 | |
| 112 | if ($name == '') |
| 113 | { |
| 114 | $name = $model; |
| 115 | } |
| 116 | |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 117 | if (in_array($name, $this->_ci_models, TRUE)) |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 118 | { |
| 119 | return; |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 120 | } |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 121 | |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 122 | $CI =& get_instance(); |
| 123 | if (isset($CI->$name)) |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 124 | { |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 125 | show_error('The model name you are loading is the name of a resource that is already being used: '.$name); |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | $model = strtolower($model); |
| 129 | |
| 130 | if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) |
| 131 | { |
| 132 | show_error('Unable to locate the model you have specified: '.$model); |
| 133 | } |
| 134 | |
| 135 | if ($db_conn !== FALSE) |
| 136 | { |
| 137 | if ($db_conn === TRUE) |
| 138 | $db_conn = ''; |
| 139 | |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 140 | $CI->load->database($db_conn, FALSE, TRUE); |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | if ( ! class_exists('Model')) |
| 144 | { |
| 145 | require_once(BASEPATH.'libraries/Model'.EXT); |
| 146 | } |
| 147 | |
| 148 | require_once(APPPATH.'models/'.$path.$model.EXT); |
| 149 | |
| 150 | $model = ucfirst($model); |
admin | 34f7f2d | 2006-10-10 08:06:42 +0000 | [diff] [blame] | 151 | |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 152 | $CI->$name = new $model(); |
| 153 | $CI->$name->_assign_libraries(); |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 154 | |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 155 | $this->_ci_models[] = $name; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 156 | } |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 157 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 158 | // -------------------------------------------------------------------- |
| 159 | |
| 160 | /** |
| 161 | * Database Loader |
| 162 | * |
| 163 | * @access public |
| 164 | * @param string the DB credentials |
| 165 | * @param bool whether to return the DB object |
| 166 | * @param bool whether to enable active record (this allows us to override the config setting) |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 167 | * @return object |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 168 | */ |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 169 | function database($params = '', $return = FALSE, $active_record = FALSE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 170 | { |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 171 | // Do we even need to load the database class? |
| 172 | if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) |
| 173 | { |
| 174 | return FALSE; |
| 175 | } |
| 176 | |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 177 | require_once(BASEPATH.'database/DB'.EXT); |
admin | fd2750b | 2006-10-06 17:29:12 +0000 | [diff] [blame] | 178 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 179 | if ($return === TRUE) |
| 180 | { |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 181 | return DB($params, $active_record); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 182 | } |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 183 | |
admin | 2b47ea4 | 2006-10-24 00:15:02 +0000 | [diff] [blame] | 184 | // Grab the super object |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 185 | $CI =& get_instance(); |
admin | 2b47ea4 | 2006-10-24 00:15:02 +0000 | [diff] [blame] | 186 | |
| 187 | // Initialize the db variable. Needed to prevent |
| 188 | // reference errors with some configurations |
| 189 | $CI->db = ''; |
| 190 | |
| 191 | // Load the DB class |
| 192 | $CI->db =& DB($params, $active_record); |
| 193 | |
| 194 | // Assign the DB object to any existing models |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 195 | $this->_ci_assign_to_models(); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 196 | } |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 197 | |
| 198 | // -------------------------------------------------------------------- |
| 199 | |
| 200 | /** |
| 201 | * Load the Utilities Class |
| 202 | * |
| 203 | * @access public |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 204 | * @return string |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 205 | */ |
| 206 | function dbutil() |
| 207 | { |
| 208 | if ( ! class_exists('CI_DB')) |
| 209 | { |
| 210 | $this->database(); |
| 211 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 212 | |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 213 | $CI =& get_instance(); |
| 214 | |
| 215 | require_once(BASEPATH.'database/DB_utility'.EXT); |
| 216 | require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); |
| 217 | $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; |
| 218 | |
| 219 | $CI->dbutil = new $class(); |
| 220 | $CI->load->_ci_assign_to_models(); |
| 221 | } |
| 222 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 223 | // -------------------------------------------------------------------- |
| 224 | |
| 225 | /** |
| 226 | * Load View |
| 227 | * |
| 228 | * This function is used to load a "view" file. It has three parameters: |
| 229 | * |
| 230 | * 1. The name of the "view" file to be included. |
| 231 | * 2. An associative array of data to be extracted for use in the view. |
| 232 | * 3. TRUE/FALSE - whether to return the data or load it. In |
admin | b807f32 | 2006-10-20 04:55:37 +0000 | [diff] [blame] | 233 | * some cases it's advantageous to be able to return data so that |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 234 | * a developer can process it in some way. |
| 235 | * |
| 236 | * @access public |
| 237 | * @param string |
| 238 | * @param array |
| 239 | * @param bool |
| 240 | * @return void |
| 241 | */ |
| 242 | function view($view, $vars = array(), $return = FALSE) |
| 243 | { |
| 244 | return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return)); |
| 245 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 246 | |
| 247 | // -------------------------------------------------------------------- |
| 248 | |
| 249 | /** |
| 250 | * Load File |
| 251 | * |
| 252 | * This is a generic file loader |
| 253 | * |
| 254 | * @access public |
| 255 | * @param string |
| 256 | * @param bool |
| 257 | * @return string |
| 258 | */ |
| 259 | function file($path, $return = FALSE) |
| 260 | { |
| 261 | return $this->_ci_load(array('path' => $path, 'return' => $return)); |
| 262 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 263 | |
| 264 | // -------------------------------------------------------------------- |
| 265 | |
| 266 | /** |
| 267 | * Set Variables |
| 268 | * |
admin | b807f32 | 2006-10-20 04:55:37 +0000 | [diff] [blame] | 269 | * Once variables are set they become available within |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 270 | * the controller class and its "view" files. |
| 271 | * |
| 272 | * @access public |
| 273 | * @param array |
| 274 | * @return void |
| 275 | */ |
| 276 | function vars($vars = array()) |
| 277 | { |
| 278 | $vars = $this->_ci_object_to_array($vars); |
| 279 | |
| 280 | if (is_array($vars) AND count($vars) > 0) |
| 281 | { |
| 282 | foreach ($vars as $key => $val) |
| 283 | { |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 284 | $this->_ci_cached_vars[$key] = $val; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 288 | |
| 289 | // -------------------------------------------------------------------- |
| 290 | |
| 291 | /** |
| 292 | * Load Helper |
| 293 | * |
| 294 | * This function loads the specified helper file. |
| 295 | * |
| 296 | * @access public |
| 297 | * @param mixed |
| 298 | * @return void |
| 299 | */ |
| 300 | function helper($helpers = array()) |
| 301 | { |
| 302 | if ( ! is_array($helpers)) |
| 303 | { |
| 304 | $helpers = array($helpers); |
| 305 | } |
| 306 | |
| 307 | foreach ($helpers as $helper) |
| 308 | { |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 309 | if (isset($this->_ci_helpers[$helper])) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 310 | { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); |
| 315 | |
admin | 480da81 | 2006-09-20 21:11:04 +0000 | [diff] [blame] | 316 | if (file_exists(APPPATH.'helpers/'.$helper.EXT)) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 317 | { |
admin | 480da81 | 2006-09-20 21:11:04 +0000 | [diff] [blame] | 318 | include_once(APPPATH.'helpers/'.$helper.EXT); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 319 | } |
admin | 480da81 | 2006-09-20 21:11:04 +0000 | [diff] [blame] | 320 | else |
| 321 | { |
| 322 | if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) |
| 323 | { |
| 324 | include_once(BASEPATH.'helpers/'.$helper.EXT); |
| 325 | } |
| 326 | else |
| 327 | { |
| 328 | show_error('Unable to load the requested file: helpers/'.$helper.EXT); |
| 329 | } |
| 330 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 331 | |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 332 | $this->_ci_helpers[$helper] = TRUE; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); |
| 336 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 337 | |
| 338 | // -------------------------------------------------------------------- |
| 339 | |
| 340 | /** |
| 341 | * Load Helpers |
| 342 | * |
| 343 | * This is simply an alias to the above function in case the |
| 344 | * user has written the plural form of this function. |
| 345 | * |
| 346 | * @access public |
| 347 | * @param array |
| 348 | * @return void |
| 349 | */ |
| 350 | function helpers($helpers = array()) |
| 351 | { |
| 352 | $this->helper($helpers); |
| 353 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 354 | |
| 355 | // -------------------------------------------------------------------- |
| 356 | |
| 357 | /** |
| 358 | * Load Plugin |
| 359 | * |
| 360 | * This function loads the specified plugin. |
| 361 | * |
| 362 | * @access public |
| 363 | * @param array |
| 364 | * @return void |
| 365 | */ |
| 366 | function plugin($plugins = array()) |
| 367 | { |
| 368 | if ( ! is_array($plugins)) |
| 369 | { |
| 370 | $plugins = array($plugins); |
| 371 | } |
| 372 | |
| 373 | foreach ($plugins as $plugin) |
| 374 | { |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 375 | if (isset($this->_ci_plugins[$plugin])) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 376 | { |
| 377 | continue; |
| 378 | } |
| 379 | |
admin | 480da81 | 2006-09-20 21:11:04 +0000 | [diff] [blame] | 380 | $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 381 | |
admin | 480da81 | 2006-09-20 21:11:04 +0000 | [diff] [blame] | 382 | if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 383 | { |
admin | 480da81 | 2006-09-20 21:11:04 +0000 | [diff] [blame] | 384 | include_once(APPPATH.'plugins/'.$plugin.EXT); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 385 | } |
admin | 480da81 | 2006-09-20 21:11:04 +0000 | [diff] [blame] | 386 | else |
| 387 | { |
| 388 | if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) |
| 389 | { |
| 390 | include_once(BASEPATH.'plugins/'.$plugin.EXT); |
| 391 | } |
| 392 | else |
| 393 | { |
| 394 | show_error('Unable to load the requested file: plugins/'.$plugin.EXT); |
| 395 | } |
| 396 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 397 | |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 398 | $this->_ci_plugins[$plugin] = TRUE; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); |
| 402 | } |
admin | fd2750b | 2006-10-06 17:29:12 +0000 | [diff] [blame] | 403 | |
| 404 | // -------------------------------------------------------------------- |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 405 | |
admin | fd2750b | 2006-10-06 17:29:12 +0000 | [diff] [blame] | 406 | /** |
| 407 | * Load Plugins |
| 408 | * |
| 409 | * This is simply an alias to the above function in case the |
| 410 | * user has written the plural form of this function. |
| 411 | * |
| 412 | * @access public |
| 413 | * @param array |
| 414 | * @return void |
| 415 | */ |
| 416 | function plugins($plugins = array()) |
| 417 | { |
| 418 | $this->plugin($plugins); |
| 419 | } |
| 420 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 421 | // -------------------------------------------------------------------- |
| 422 | |
| 423 | /** |
| 424 | * Load Script |
| 425 | * |
| 426 | * This function loads the specified include file from the |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 427 | * application/scripts/ folder. |
| 428 | * |
| 429 | * NOTE: This feature has been deprecated but it will remain available |
| 430 | * for legacy users. |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 431 | * |
| 432 | * @access public |
| 433 | * @param array |
| 434 | * @return void |
| 435 | */ |
| 436 | function script($scripts = array()) |
| 437 | { |
| 438 | if ( ! is_array($scripts)) |
| 439 | { |
| 440 | $scripts = array($scripts); |
| 441 | } |
| 442 | |
| 443 | foreach ($scripts as $script) |
| 444 | { |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 445 | if (isset($this->_ci_scripts[$script])) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 446 | { |
| 447 | continue; |
| 448 | } |
| 449 | |
| 450 | $script = strtolower(str_replace(EXT, '', $script)); |
| 451 | |
| 452 | if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) |
| 453 | { |
| 454 | show_error('Unable to load the requested script: scripts/'.$script.EXT); |
| 455 | } |
| 456 | |
| 457 | include_once(APPPATH.'scripts/'.$script.EXT); |
| 458 | |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 459 | $this->_ci_scripts[$script] = TRUE; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); |
| 463 | } |
admin | fd2750b | 2006-10-06 17:29:12 +0000 | [diff] [blame] | 464 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 465 | // -------------------------------------------------------------------- |
| 466 | |
| 467 | /** |
| 468 | * Loads a language file |
| 469 | * |
| 470 | * @access public |
| 471 | * @param string |
| 472 | * @return void |
| 473 | */ |
| 474 | function language($file = '', $lang = '', $return = FALSE) |
| 475 | { |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 476 | $CI =& get_instance(); |
| 477 | return $CI->lang->load($file, $lang, $return); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 478 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 479 | |
| 480 | // -------------------------------------------------------------------- |
| 481 | |
| 482 | /** |
| 483 | * Loads a config file |
| 484 | * |
| 485 | * @access public |
| 486 | * @param string |
| 487 | * @return void |
| 488 | */ |
| 489 | function config($file = '') |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 490 | { |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 491 | $CI =& get_instance(); |
| 492 | $CI->config->load($file); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 493 | } |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 494 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 495 | // -------------------------------------------------------------------- |
| 496 | |
| 497 | /** |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 498 | * Scaffolding Loader |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 499 | * |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 500 | * This initializing function works a bit different than the |
| 501 | * others. It doesn't load the class. Instead, it simply |
| 502 | * sets a flag indicating that scaffolding is allowed to be |
| 503 | * used. The actual scaffolding function below is |
| 504 | * called by the front controller based on whether the |
| 505 | * second segment of the URL matches the "secret" scaffolding |
| 506 | * word stored in the application/config/routes.php |
| 507 | * |
| 508 | * @access public |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 509 | * @param string |
| 510 | * @return void |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 511 | */ |
| 512 | function scaffolding($table = '') |
| 513 | { |
| 514 | if ($table === FALSE) |
| 515 | { |
| 516 | show_error('You must include the name of the table you would like access when you initialize scaffolding'); |
| 517 | } |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 518 | |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 519 | $CI =& get_instance(); |
| 520 | $CI->_ci_scaffolding = TRUE; |
| 521 | $CI->_ci_scaff_table = $table; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 522 | } |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 523 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 524 | // -------------------------------------------------------------------- |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 525 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 526 | /** |
| 527 | * Loader |
| 528 | * |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 529 | * This function is used to load views and files. |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 530 | * |
| 531 | * @access private |
| 532 | * @param array |
| 533 | * @return void |
| 534 | */ |
| 535 | function _ci_load($data) |
admin | 212a3fa | 2006-09-23 04:22:39 +0000 | [diff] [blame] | 536 | { |
admin | b807f32 | 2006-10-20 04:55:37 +0000 | [diff] [blame] | 537 | // This allows anything loaded using $this->load (views, files, etc.) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 538 | // to become accessible from within the Controller and Model functions. |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 539 | // Only needed when running PHP 5 |
| 540 | |
admin | 1e30398 | 2006-10-10 16:35:43 +0000 | [diff] [blame] | 541 | if ($this->_ci_is_instance()) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 542 | { |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 543 | $CI =& get_instance(); |
| 544 | foreach (get_object_vars($CI) as $key => $var) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 545 | { |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 546 | if ( ! isset($this->$key)) |
| 547 | { |
| 548 | $this->$key =& $CI->$key; |
| 549 | } |
admin | e79dc71 | 2006-09-26 03:52:45 +0000 | [diff] [blame] | 550 | } |
| 551 | } |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 552 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 553 | // Set the default data variables |
| 554 | foreach (array('view', 'vars', 'path', 'return') as $val) |
| 555 | { |
| 556 | $$val = ( ! isset($data[$val])) ? FALSE : $data[$val]; |
| 557 | } |
| 558 | |
| 559 | /* |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 560 | * Extract and cache variables |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 561 | * |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 562 | * You can either set variables using the dedicated $this->load_vars() |
| 563 | * function or via the second parameter of this function. We'll merge |
| 564 | * the two types and cache them so that views that are embedded within |
admin | 212a3fa | 2006-09-23 04:22:39 +0000 | [diff] [blame] | 565 | * other views can have access to these variables. |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 566 | */ |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 567 | if (is_array($vars)) |
| 568 | { |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 569 | $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $vars); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 570 | } |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 571 | extract($this->_ci_cached_vars); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 572 | |
| 573 | // Set the path to the requested file |
| 574 | if ($path == '') |
| 575 | { |
| 576 | $ext = pathinfo($view, PATHINFO_EXTENSION); |
admin | 6ac4bea | 2006-09-02 17:46:15 +0000 | [diff] [blame] | 577 | $file = ($ext == '') ? $view.EXT : $view; |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 578 | $path = $this->_ci_view_path.$file; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 579 | } |
| 580 | else |
| 581 | { |
| 582 | $x = explode('/', $path); |
| 583 | $file = end($x); |
| 584 | } |
| 585 | |
| 586 | /* |
| 587 | * Buffer the output |
| 588 | * |
| 589 | * We buffer the output for two reasons: |
| 590 | * 1. Speed. You get a significant speed boost. |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 591 | * 2. So that the final rendered template can be |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 592 | * post-processed by the output class. Why do we |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 593 | * need post processing? For one thing, in order to |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 594 | * show the elapsed page load time. Unless we |
| 595 | * can intercept the content right before it's sent to |
admin | b807f32 | 2006-10-20 04:55:37 +0000 | [diff] [blame] | 596 | * the browser and then stop the timer it won't be accurate. |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 597 | */ |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 598 | if ( ! file_exists($path)) |
| 599 | { |
| 600 | show_error('Unable to load the requested file: '.$file); |
| 601 | } |
| 602 | |
| 603 | ob_start(); |
admin | 30578ea | 2006-10-17 02:31:06 +0000 | [diff] [blame] | 604 | |
| 605 | // If the PHP installation does not support short tags we'll |
| 606 | // do a little string replacement, changing the short tags |
| 607 | // to standard PHP echo statements. |
admin | 30578ea | 2006-10-17 02:31:06 +0000 | [diff] [blame] | 608 | |
admin | 81a3681 | 2006-10-17 03:40:51 +0000 | [diff] [blame] | 609 | if ((bool) @ini_get('short_open_tag') === FALSE) |
| 610 | { |
| 611 | echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($path))).'<?php '); |
admin | 30578ea | 2006-10-17 02:31:06 +0000 | [diff] [blame] | 612 | } |
| 613 | else |
| 614 | { |
| 615 | include($path); |
| 616 | } |
| 617 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 618 | log_message('debug', 'File loaded: '.$path); |
| 619 | |
| 620 | // Return the file data if requested to |
| 621 | if ($return === TRUE) |
| 622 | { |
| 623 | $buffer = ob_get_contents(); |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 624 | ob_end_clean(); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 625 | |
| 626 | return $buffer; |
| 627 | } |
| 628 | |
| 629 | /* |
| 630 | * Flush the buffer... or buff the flusher? |
| 631 | * |
admin | 212a3fa | 2006-09-23 04:22:39 +0000 | [diff] [blame] | 632 | * In order to permit views to be nested within |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 633 | * other views, we need to flush the content back out whenever |
| 634 | * we are beyond the first level of output buffering so that |
| 635 | * it can be seen and included properly by the first included |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 636 | * template and any subsequent ones. Oy! |
| 637 | * |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 638 | */ |
| 639 | if (ob_get_level() > $this->_ci_ob_level + 1) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 640 | { |
| 641 | ob_end_flush(); |
| 642 | } |
| 643 | else |
| 644 | { |
admin | 34f7f2d | 2006-10-10 08:06:42 +0000 | [diff] [blame] | 645 | // PHP 4 requires that we use a global |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 646 | global $OUT; |
| 647 | $OUT->set_output(ob_get_contents()); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 648 | ob_end_clean(); |
| 649 | } |
| 650 | } |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 651 | |
| 652 | // -------------------------------------------------------------------- |
| 653 | |
| 654 | /** |
| 655 | * Load class |
| 656 | * |
| 657 | * This function loads the requested class. |
| 658 | * |
| 659 | * @access private |
| 660 | * @param string the item that is being loaded |
| 661 | * @param mixed any additional parameters |
| 662 | * @return void |
| 663 | */ |
admin | 5a14ea1 | 2006-10-12 20:42:55 +0000 | [diff] [blame] | 664 | function _ci_load_class($class, $params = NULL) |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 665 | { |
| 666 | // Prep the class name |
admin | 0625e19 | 2006-10-20 22:16:54 +0000 | [diff] [blame] | 667 | $class = ucfirst(strtolower(str_replace(EXT, '', $class))); |
admin | 10c3f41 | 2006-10-08 07:21:12 +0000 | [diff] [blame] | 668 | |
admin | 0625e19 | 2006-10-20 22:16:54 +0000 | [diff] [blame] | 669 | // Is this a class extension request? |
| 670 | if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) |
| 671 | { |
| 672 | if ( ! file_exists(BASEPATH.'libraries/'.$class.EXT)) |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 673 | { |
admin | 0625e19 | 2006-10-20 22:16:54 +0000 | [diff] [blame] | 674 | log_message('error', "Unable to load the requested class: ".$class); |
| 675 | show_error("Unable to load the requested class: ".$class); |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 676 | } |
admin | 0625e19 | 2006-10-20 22:16:54 +0000 | [diff] [blame] | 677 | |
| 678 | include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); |
| 679 | include_once(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); |
| 680 | |
admin | 570c161 | 2006-10-20 22:28:39 +0000 | [diff] [blame] | 681 | return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 682 | } |
admin | 10c3f41 | 2006-10-08 07:21:12 +0000 | [diff] [blame] | 683 | |
| 684 | // Lets search for the requested library file and load it. |
admin | 0625e19 | 2006-10-20 22:16:54 +0000 | [diff] [blame] | 685 | for ($i = 1; $i < 3; $i++) |
admin | 10c3f41 | 2006-10-08 07:21:12 +0000 | [diff] [blame] | 686 | { |
admin | 0625e19 | 2006-10-20 22:16:54 +0000 | [diff] [blame] | 687 | $path = ($i % 2) ? APPPATH : BASEPATH; |
admin | 570c161 | 2006-10-20 22:28:39 +0000 | [diff] [blame] | 688 | if (file_exists($path.'libraries/'.$class.EXT)) |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 689 | { |
admin | 570c161 | 2006-10-20 22:28:39 +0000 | [diff] [blame] | 690 | include_once($path.'libraries/'.$class.EXT); |
| 691 | return $this->_ci_init_class($class, '', $params); |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | |
| 695 | // If we got this far we were unable to find the requested class |
| 696 | log_message('error', "Unable to load the requested class: ".$class); |
admin | 0625e19 | 2006-10-20 22:16:54 +0000 | [diff] [blame] | 697 | show_error("Unable to load the requested class: ".$class); |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | // -------------------------------------------------------------------- |
| 701 | |
| 702 | /** |
| 703 | * Instantiates a class |
| 704 | * |
| 705 | * @access private |
| 706 | * @param string |
| 707 | * @param string |
| 708 | * @return null |
| 709 | */ |
admin | 30578ea | 2006-10-17 02:31:06 +0000 | [diff] [blame] | 710 | function _ci_init_class($class, $prefix = '', $config = FALSE) |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 711 | { |
| 712 | // Is there an associated config file for this class? |
admin | ca3dafb | 2006-10-23 01:24:11 +0000 | [diff] [blame] | 713 | if ($config === NULL) |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 714 | { |
admin | ca3dafb | 2006-10-23 01:24:11 +0000 | [diff] [blame] | 715 | $config = NULL; |
admin | 80b2bd9 | 2006-10-12 18:30:36 +0000 | [diff] [blame] | 716 | if (file_exists(APPPATH.'config/'.$class.EXT)) |
| 717 | { |
| 718 | include_once(APPPATH.'config/'.$class.EXT); |
| 719 | } |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | if ($prefix == '') |
| 723 | { |
admin | 10c3f41 | 2006-10-08 07:21:12 +0000 | [diff] [blame] | 724 | $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class; |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 725 | } |
| 726 | else |
| 727 | { |
| 728 | $name = $prefix.$class; |
| 729 | } |
admin | 2f0bac8 | 2006-10-09 17:36:45 +0000 | [diff] [blame] | 730 | |
admin | b1fddc0 | 2006-10-09 21:29:07 +0000 | [diff] [blame] | 731 | // Set the variable name we will assign the class to |
admin | 80b2bd9 | 2006-10-12 18:30:36 +0000 | [diff] [blame] | 732 | $class = strtolower($class); |
| 733 | $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; |
| 734 | |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 735 | // Instantiate the class |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 736 | $CI =& get_instance(); |
| 737 | if ($config !== NULL) |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 738 | { |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 739 | $CI->$classvar = new $name($config); |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 740 | } |
| 741 | else |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 742 | { |
| 743 | $CI->$classvar = new $name; |
| 744 | } |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 745 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 746 | |
| 747 | // -------------------------------------------------------------------- |
| 748 | |
| 749 | /** |
| 750 | * Autoloader |
| 751 | * |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 752 | * The config/autoload.php file contains an array that permits sub-systems, |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 753 | * libraries, plugins, and helpers to be loaded automatically. |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 754 | * |
| 755 | * @access private |
| 756 | * @param array |
| 757 | * @return void |
| 758 | */ |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 759 | function _ci_autoloader() |
| 760 | { |
| 761 | include_once(APPPATH.'config/autoload'.EXT); |
| 762 | |
| 763 | if ( ! isset($autoload)) |
| 764 | { |
| 765 | return FALSE; |
| 766 | } |
| 767 | |
| 768 | // Load any custome config file |
| 769 | if (count($autoload['config']) > 0) |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 770 | { |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 771 | $CI =& get_instance(); |
| 772 | foreach ($autoload['config'] as $key => $val) |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 773 | { |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 774 | $CI->config->load($val); |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | |
| 778 | // Load plugins, helpers, and scripts |
| 779 | foreach (array('helper', 'plugin', 'script') as $type) |
| 780 | { |
| 781 | if (isset($autoload[$type]) AND count($autoload[$type]) > 0) |
| 782 | { |
| 783 | $this->$type($autoload[$type]); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | // A little tweak to remain backward compatible |
| 788 | // The $autoload['core'] item was deprecated |
| 789 | if ( ! isset($autoload['libraries'])) |
| 790 | { |
| 791 | $autoload['libraries'] = $autoload['core']; |
| 792 | } |
| 793 | |
| 794 | // Load libraries |
| 795 | if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) |
| 796 | { |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 797 | // Load the database driver. |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 798 | if (in_array('database', $autoload['libraries'])) |
| 799 | { |
| 800 | $this->database(); |
| 801 | $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); |
| 802 | } |
| 803 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 804 | // Load the model class. |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 805 | if (in_array('model', $autoload['libraries'])) |
| 806 | { |
| 807 | $this->model(); |
| 808 | $autoload['libraries'] = array_diff($autoload['libraries'], array('model')); |
| 809 | } |
admin | 10c3f41 | 2006-10-08 07:21:12 +0000 | [diff] [blame] | 810 | |
| 811 | // Load scaffolding |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 812 | if (in_array('scaffolding', $autoload['libraries'])) |
| 813 | { |
| 814 | $this->scaffolding(); |
| 815 | $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); |
| 816 | } |
| 817 | |
admin | 10c3f41 | 2006-10-08 07:21:12 +0000 | [diff] [blame] | 818 | // Load all other libraries |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 819 | foreach ($autoload['libraries'] as $item) |
| 820 | { |
| 821 | $this->library($item); |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | // -------------------------------------------------------------------- |
| 827 | |
| 828 | /** |
| 829 | * Assign to Models |
| 830 | * |
| 831 | * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) |
admin | bd6bee7 | 2006-10-21 19:39:00 +0000 | [diff] [blame] | 832 | * will be available to models, if any exist. |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 833 | * |
admin | 34f7f2d | 2006-10-10 08:06:42 +0000 | [diff] [blame] | 834 | * @access private |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 835 | * @param object |
| 836 | * @return array |
| 837 | */ |
| 838 | function _ci_assign_to_models() |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 839 | { |
admin | 2bc1385 | 2006-10-24 23:16:17 +0000 | [diff] [blame] | 840 | if (count($this->_ci_models) == 0) |
| 841 | { |
| 842 | return; |
| 843 | } |
| 844 | |
admin | 1e30398 | 2006-10-10 16:35:43 +0000 | [diff] [blame] | 845 | if ($this->_ci_is_instance()) |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 846 | { |
| 847 | $CI =& get_instance(); |
| 848 | foreach ($this->_ci_models as $model) |
| 849 | { |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 850 | $CI->$model->_assign_libraries(); |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | else |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 854 | { |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 855 | foreach ($this->_ci_models as $model) |
| 856 | { |
admin | 0aef222 | 2006-10-12 18:00:22 +0000 | [diff] [blame] | 857 | $this->$model->_assign_libraries(); |
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 858 | } |
| 859 | } |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 860 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 861 | |
| 862 | // -------------------------------------------------------------------- |
| 863 | |
| 864 | /** |
| 865 | * Object to Array |
| 866 | * |
admin | bd6bee7 | 2006-10-21 19:39:00 +0000 | [diff] [blame] | 867 | * Takes an object as input and converts the class variables to array key/vals |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 868 | * |
admin | 34f7f2d | 2006-10-10 08:06:42 +0000 | [diff] [blame] | 869 | * @access private |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 870 | * @param object |
| 871 | * @return array |
| 872 | */ |
| 873 | function _ci_object_to_array($object) |
| 874 | { |
admin | 2e5872a | 2006-09-06 02:32:55 +0000 | [diff] [blame] | 875 | return (is_object($object)) ? get_object_vars($object) : $object; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 876 | } |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 877 | |
admin | 34f7f2d | 2006-10-10 08:06:42 +0000 | [diff] [blame] | 878 | // -------------------------------------------------------------------- |
| 879 | |
| 880 | /** |
| 881 | * Determines whether we should use the CI instance or $this |
| 882 | * |
| 883 | * @access private |
| 884 | * @return bool |
| 885 | */ |
admin | 1e30398 | 2006-10-10 16:35:43 +0000 | [diff] [blame] | 886 | function _ci_is_instance() |
admin | 34f7f2d | 2006-10-10 08:06:42 +0000 | [diff] [blame] | 887 | { |
| 888 | if ($this->_ci_is_php5 == TRUE) |
| 889 | { |
| 890 | return TRUE; |
| 891 | } |
| 892 | |
| 893 | global $CI; |
| 894 | return (is_object($CI)) ? TRUE : FALSE; |
| 895 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 896 | |
| 897 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 898 | ?> |