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