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