blob: 05ee93959eadacb22ebadc151a2176ce51ab5e0f [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<?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 */
29class CI_Loader {
30
admin8f0a8f62006-10-07 01:17:25 +000031 var $CI;
adminb0dd10f2006-08-25 17:25:49 +000032 var $ob_level;
33 var $cached_vars = array();
adminb3ab70b2006-10-07 03:07:29 +000034 var $models = array();
adminb0dd10f2006-08-25 17:25:49 +000035 var $helpers = array();
36 var $plugins = array();
37 var $scripts = array();
adminb0dd10f2006-08-25 17:25:49 +000038 var $view_path = '';
39
40 /**
41 * Constructor
42 *
43 * Sets the path to the view files and gets the initial output
44 * buffering level
45 *
46 * @access public
47 */
48 function CI_Loader()
49 {
admin8f0a8f62006-10-07 01:17:25 +000050 $this->CI =& get_instance();
51
adminb0dd10f2006-08-25 17:25:49 +000052 $this->view_path = APPPATH.'views/';
53 $this->ob_level = ob_get_level();
54
55 log_message('debug', "Loader Class Initialized");
56 }
adminb0dd10f2006-08-25 17:25:49 +000057
58 // --------------------------------------------------------------------
59
60 /**
61 * Class Loader
62 *
63 * This function lets users load and instantiate classes.
64 * It is designed to be called from a user's app controllers.
65 *
66 * @access public
67 * @param string the name of the class
68 * @param mixed any initialization parameters
69 * @return void
70 */
admin7981a9a2006-09-26 07:52:09 +000071 function library($class, $param = NULL)
adminb0dd10f2006-08-25 17:25:49 +000072 {
73 if ($class == '')
74 return;
75
admin8f0a8f62006-10-07 01:17:25 +000076 $this->_ci_load_class($class, $param);
77 $this->_ci_assign_to_models();
adminb0dd10f2006-08-25 17:25:49 +000078 }
adminb0dd10f2006-08-25 17:25:49 +000079
80 // --------------------------------------------------------------------
81
82 /**
83 * Model Loader
84 *
85 * This function lets users load and instantiate models.
86 *
87 * @access public
88 * @param string the name of the class
89 * @param mixed any initialization parameters
90 * @return void
91 */
92 function model($model, $name = '', $db_conn = FALSE)
93 {
94 if ($model == '')
95 return;
96
admin8f0a8f62006-10-07 01:17:25 +000097 // Is the model in a sub-folder?
98 // If so, parse out the filename and path.
99 if (strpos($model, '/') === FALSE)
100 {
101 $path = '';
102 }
103 else
104 {
105 $x = explode('/', $model);
106 $model = end($x);
107 unset($x[count($x)-1]);
108 $path = implode('/', $x).'/';
109 }
110
111 if ($name == '')
112 {
113 $name = $model;
114 }
115
116 if (in_array($name, $this->models, TRUE))
117 {
118 return;
119 }
120
121 if (isset($this->CI->$name))
122 {
123 show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
124 }
125
126 $model = strtolower($model);
127
128 if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT))
129 {
130 show_error('Unable to locate the model you have specified: '.$model);
131 }
132
133 if ($db_conn !== FALSE)
134 {
135 if ($db_conn === TRUE)
136 $db_conn = '';
137
138 $this->CI->load->database($db_conn, FALSE, TRUE);
139 }
140
141 if ( ! class_exists('Model'))
142 {
143 require_once(BASEPATH.'libraries/Model'.EXT);
144 }
145
146 require_once(APPPATH.'models/'.$path.$model.EXT);
147
148 $model = ucfirst($model);
149 $this->CI->$name = new $model();
150 $this->models[] = $name;
151 $this->_ci_assign_to_models();
adminb0dd10f2006-08-25 17:25:49 +0000152 }
adminb0dd10f2006-08-25 17:25:49 +0000153
154 // --------------------------------------------------------------------
155
156 /**
157 * Database Loader
158 *
159 * @access public
160 * @param string the DB credentials
161 * @param bool whether to return the DB object
162 * @param bool whether to enable active record (this allows us to override the config setting)
admina5e812c2006-09-25 02:17:30 +0000163 * @return object
adminb0dd10f2006-08-25 17:25:49 +0000164 */
admin8f0a8f62006-10-07 01:17:25 +0000165 function database($params = '', $return = FALSE, $active_record = FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000166 {
admin8f0a8f62006-10-07 01:17:25 +0000167 require_once(BASEPATH.'database/DB'.EXT);
adminfd2750b2006-10-06 17:29:12 +0000168
adminb0dd10f2006-08-25 17:25:49 +0000169 if ($return === TRUE)
170 {
admin8f0a8f62006-10-07 01:17:25 +0000171 return DB($params, $return, $active_record);
adminb0dd10f2006-08-25 17:25:49 +0000172 }
173 else
174 {
admin8f0a8f62006-10-07 01:17:25 +0000175 DB($params, $return, $active_record);
176 $this->_ci_assign_to_models();
adminb0dd10f2006-08-25 17:25:49 +0000177 }
178 }
adminb0dd10f2006-08-25 17:25:49 +0000179
adminb0dd10f2006-08-25 17:25:49 +0000180 // --------------------------------------------------------------------
181
182 /**
183 * Load View
184 *
185 * This function is used to load a "view" file. It has three parameters:
186 *
187 * 1. The name of the "view" file to be included.
188 * 2. An associative array of data to be extracted for use in the view.
189 * 3. TRUE/FALSE - whether to return the data or load it. In
190 * some cases it's advantageous to be able to retun data so that
191 * a developer can process it in some way.
192 *
193 * @access public
194 * @param string
195 * @param array
196 * @param bool
197 * @return void
198 */
199 function view($view, $vars = array(), $return = FALSE)
200 {
201 return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return));
202 }
adminb0dd10f2006-08-25 17:25:49 +0000203
204 // --------------------------------------------------------------------
205
206 /**
207 * Load File
208 *
209 * This is a generic file loader
210 *
211 * @access public
212 * @param string
213 * @param bool
214 * @return string
215 */
216 function file($path, $return = FALSE)
217 {
218 return $this->_ci_load(array('path' => $path, 'return' => $return));
219 }
adminb0dd10f2006-08-25 17:25:49 +0000220
221 // --------------------------------------------------------------------
222
223 /**
224 * Set Variables
225 *
226 * Once variables are set they become availabe within
227 * the controller class and its "view" files.
228 *
229 * @access public
230 * @param array
231 * @return void
232 */
233 function vars($vars = array())
234 {
235 $vars = $this->_ci_object_to_array($vars);
236
237 if (is_array($vars) AND count($vars) > 0)
238 {
239 foreach ($vars as $key => $val)
240 {
241 $this->cached_vars[$key] = $val;
242 }
243 }
244 }
adminb0dd10f2006-08-25 17:25:49 +0000245
246 // --------------------------------------------------------------------
247
248 /**
249 * Load Helper
250 *
251 * This function loads the specified helper file.
252 *
253 * @access public
254 * @param mixed
255 * @return void
256 */
257 function helper($helpers = array())
258 {
259 if ( ! is_array($helpers))
260 {
261 $helpers = array($helpers);
262 }
263
264 foreach ($helpers as $helper)
265 {
266 if (isset($this->helpers[$helper]))
267 {
268 continue;
269 }
270
271 $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper');
272
admin480da812006-09-20 21:11:04 +0000273 if (file_exists(APPPATH.'helpers/'.$helper.EXT))
adminb0dd10f2006-08-25 17:25:49 +0000274 {
admin480da812006-09-20 21:11:04 +0000275 include_once(APPPATH.'helpers/'.$helper.EXT);
adminb0dd10f2006-08-25 17:25:49 +0000276 }
admin480da812006-09-20 21:11:04 +0000277 else
278 {
279 if (file_exists(BASEPATH.'helpers/'.$helper.EXT))
280 {
281 include_once(BASEPATH.'helpers/'.$helper.EXT);
282 }
283 else
284 {
285 show_error('Unable to load the requested file: helpers/'.$helper.EXT);
286 }
287 }
adminb0dd10f2006-08-25 17:25:49 +0000288
289 $this->helpers[$helper] = TRUE;
290 }
291
292 log_message('debug', 'Helpers loaded: '.implode(', ', $helpers));
293 }
adminb0dd10f2006-08-25 17:25:49 +0000294
295 // --------------------------------------------------------------------
296
297 /**
298 * Load Helpers
299 *
300 * This is simply an alias to the above function in case the
301 * user has written the plural form of this function.
302 *
303 * @access public
304 * @param array
305 * @return void
306 */
307 function helpers($helpers = array())
308 {
309 $this->helper($helpers);
310 }
adminb0dd10f2006-08-25 17:25:49 +0000311
312 // --------------------------------------------------------------------
313
314 /**
315 * Load Plugin
316 *
317 * This function loads the specified plugin.
318 *
319 * @access public
320 * @param array
321 * @return void
322 */
323 function plugin($plugins = array())
324 {
325 if ( ! is_array($plugins))
326 {
327 $plugins = array($plugins);
328 }
329
330 foreach ($plugins as $plugin)
331 {
332 if (isset($this->plugins[$plugin]))
333 {
334 continue;
335 }
336
admin480da812006-09-20 21:11:04 +0000337 $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi');
adminb0dd10f2006-08-25 17:25:49 +0000338
admin480da812006-09-20 21:11:04 +0000339 if (file_exists(APPPATH.'plugins/'.$plugin.EXT))
adminb0dd10f2006-08-25 17:25:49 +0000340 {
admin480da812006-09-20 21:11:04 +0000341 include_once(APPPATH.'plugins/'.$plugin.EXT);
adminb0dd10f2006-08-25 17:25:49 +0000342 }
admin480da812006-09-20 21:11:04 +0000343 else
344 {
345 if (file_exists(BASEPATH.'plugins/'.$plugin.EXT))
346 {
347 include_once(BASEPATH.'plugins/'.$plugin.EXT);
348 }
349 else
350 {
351 show_error('Unable to load the requested file: plugins/'.$plugin.EXT);
352 }
353 }
adminb0dd10f2006-08-25 17:25:49 +0000354
355 $this->plugins[$plugin] = TRUE;
356 }
357
358 log_message('debug', 'Plugins loaded: '.implode(', ', $plugins));
359 }
adminfd2750b2006-10-06 17:29:12 +0000360
361 // --------------------------------------------------------------------
adminb0dd10f2006-08-25 17:25:49 +0000362
adminfd2750b2006-10-06 17:29:12 +0000363 /**
364 * Load Plugins
365 *
366 * This is simply an alias to the above function in case the
367 * user has written the plural form of this function.
368 *
369 * @access public
370 * @param array
371 * @return void
372 */
373 function plugins($plugins = array())
374 {
375 $this->plugin($plugins);
376 }
377
adminb0dd10f2006-08-25 17:25:49 +0000378 // --------------------------------------------------------------------
379
380 /**
381 * Load Script
382 *
383 * This function loads the specified include file from the
admin83b05a82006-09-25 21:06:46 +0000384 * application/scripts/ folder.
385 *
386 * NOTE: This feature has been deprecated but it will remain available
387 * for legacy users.
adminb0dd10f2006-08-25 17:25:49 +0000388 *
389 * @access public
390 * @param array
391 * @return void
392 */
393 function script($scripts = array())
394 {
395 if ( ! is_array($scripts))
396 {
397 $scripts = array($scripts);
398 }
399
400 foreach ($scripts as $script)
401 {
402 if (isset($this->scripts[$script]))
403 {
404 continue;
405 }
406
407 $script = strtolower(str_replace(EXT, '', $script));
408
409 if ( ! file_exists(APPPATH.'scripts/'.$script.EXT))
410 {
411 show_error('Unable to load the requested script: scripts/'.$script.EXT);
412 }
413
414 include_once(APPPATH.'scripts/'.$script.EXT);
415
416 $this->scripts[$script] = TRUE;
417 }
418
419 log_message('debug', 'Scripts loaded: '.implode(', ', $scripts));
420 }
adminfd2750b2006-10-06 17:29:12 +0000421
adminb0dd10f2006-08-25 17:25:49 +0000422 // --------------------------------------------------------------------
423
424 /**
425 * Loads a language file
426 *
427 * @access public
428 * @param string
429 * @return void
430 */
431 function language($file = '', $lang = '', $return = FALSE)
432 {
admin8f0a8f62006-10-07 01:17:25 +0000433 return $this->CI->lang->load($file, $lang, $return);
adminb0dd10f2006-08-25 17:25:49 +0000434 }
adminb0dd10f2006-08-25 17:25:49 +0000435
436 // --------------------------------------------------------------------
437
438 /**
439 * Loads a config file
440 *
441 * @access public
442 * @param string
443 * @return void
444 */
445 function config($file = '')
446 {
admin8f0a8f62006-10-07 01:17:25 +0000447 $this->CI->config->load($file);
adminb0dd10f2006-08-25 17:25:49 +0000448 }
admin8f0a8f62006-10-07 01:17:25 +0000449
adminb0dd10f2006-08-25 17:25:49 +0000450 // --------------------------------------------------------------------
451
452 /**
admin8f0a8f62006-10-07 01:17:25 +0000453 * Scaffolding Loader
adminb0dd10f2006-08-25 17:25:49 +0000454 *
admin8f0a8f62006-10-07 01:17:25 +0000455 * This initializing function works a bit different than the
456 * others. It doesn't load the class. Instead, it simply
457 * sets a flag indicating that scaffolding is allowed to be
458 * used. The actual scaffolding function below is
459 * called by the front controller based on whether the
460 * second segment of the URL matches the "secret" scaffolding
461 * word stored in the application/config/routes.php
462 *
463 * @access public
adminb0dd10f2006-08-25 17:25:49 +0000464 * @param string
465 * @return void
admin8f0a8f62006-10-07 01:17:25 +0000466 */
467 function scaffolding($table = '')
468 {
469 if ($table === FALSE)
470 {
471 show_error('You must include the name of the table you would like access when you initialize scaffolding');
472 }
473
474 $this->CI->_ci_scaffolding = TRUE;
475 $this->CI->_ci_scaff_table = $table;
adminb0dd10f2006-08-25 17:25:49 +0000476 }
admin8f0a8f62006-10-07 01:17:25 +0000477
adminb0dd10f2006-08-25 17:25:49 +0000478 // --------------------------------------------------------------------
admin8f0a8f62006-10-07 01:17:25 +0000479
adminb0dd10f2006-08-25 17:25:49 +0000480 /**
481 * Loader
482 *
admin8f0a8f62006-10-07 01:17:25 +0000483 * This function is used to load views and files.
adminb0dd10f2006-08-25 17:25:49 +0000484 *
485 * @access private
486 * @param array
487 * @return void
488 */
489 function _ci_load($data)
admin212a3fa2006-09-23 04:22:39 +0000490 {
adminb0dd10f2006-08-25 17:25:49 +0000491 // This allows anything loaded using $this->load (viwes, files, etc.)
492 // to become accessible from within the Controller and Model functions.
admin8f0a8f62006-10-07 01:17:25 +0000493 foreach (get_object_vars($this->CI) as $key => $var)
adminb0dd10f2006-08-25 17:25:49 +0000494 {
admine79dc712006-09-26 03:52:45 +0000495 if (is_object($var))
adminb0dd10f2006-08-25 17:25:49 +0000496 {
admin8f0a8f62006-10-07 01:17:25 +0000497 $this->$key =& $this->CI->$key;
admine79dc712006-09-26 03:52:45 +0000498 }
499 }
500
adminb0dd10f2006-08-25 17:25:49 +0000501 // Set the default data variables
502 foreach (array('view', 'vars', 'path', 'return') as $val)
503 {
504 $$val = ( ! isset($data[$val])) ? FALSE : $data[$val];
505 }
506
507 /*
admin83b05a82006-09-25 21:06:46 +0000508 * Extract and cache variables
adminb0dd10f2006-08-25 17:25:49 +0000509 *
admin212a3fa2006-09-23 04:22:39 +0000510 * You can either set variables using the dedicated $this->load_vars()
511 * function or via the second parameter of this function. We'll merge
512 * the two types and cache them so that views that are embedded within
513 * other views can have access to these variables.
adminb0dd10f2006-08-25 17:25:49 +0000514 */
adminb0dd10f2006-08-25 17:25:49 +0000515 if (is_array($vars))
516 {
517 $this->cached_vars = array_merge($this->cached_vars, $vars);
518 }
519 extract($this->cached_vars);
520
521 // Set the path to the requested file
522 if ($path == '')
523 {
524 $ext = pathinfo($view, PATHINFO_EXTENSION);
admin6ac4bea2006-09-02 17:46:15 +0000525 $file = ($ext == '') ? $view.EXT : $view;
adminb0dd10f2006-08-25 17:25:49 +0000526 $path = $this->view_path.$file;
527 }
528 else
529 {
530 $x = explode('/', $path);
531 $file = end($x);
532 }
533
534 /*
535 * Buffer the output
536 *
537 * We buffer the output for two reasons:
538 * 1. Speed. You get a significant speed boost.
539 * 2. So that the final rendered template can be
540 * post-processed by the output class. Why do we
541 * need post processing? For one thing, in order to
542 * show the elapsed page load time. Unless we
543 * can intercept the content right before it's sent to
admin212a3fa2006-09-23 04:22:39 +0000544 * the browser and then stop the timer it won't be acurate.
adminb0dd10f2006-08-25 17:25:49 +0000545 */
adminb0dd10f2006-08-25 17:25:49 +0000546 if ( ! file_exists($path))
547 {
548 show_error('Unable to load the requested file: '.$file);
549 }
550
551 ob_start();
552
553 include($path);
554 log_message('debug', 'File loaded: '.$path);
555
556 // Return the file data if requested to
557 if ($return === TRUE)
558 {
559 $buffer = ob_get_contents();
560 ob_end_clean();
561
562 return $buffer;
563 }
564
565 /*
566 * Flush the buffer... or buff the flusher?
567 *
admin212a3fa2006-09-23 04:22:39 +0000568 * In order to permit views to be nested within
adminb0dd10f2006-08-25 17:25:49 +0000569 * other views, we need to flush the content back out whenever
570 * we are beyond the first level of output buffering so that
571 * it can be seen and included properly by the first included
572 * template and any subsequent ones. Oy!
573 *
574 */
575 if (ob_get_level() > $this->ob_level + 1)
576 {
577 ob_end_flush();
578 }
579 else
580 {
admin8f0a8f62006-10-07 01:17:25 +0000581 $this->CI->output->set_output(ob_get_contents());
adminb0dd10f2006-08-25 17:25:49 +0000582 ob_end_clean();
583 }
584 }
admin8f0a8f62006-10-07 01:17:25 +0000585
586 // --------------------------------------------------------------------
587
588 /**
589 * Load class
590 *
591 * This function loads the requested class.
592 *
593 * @access private
594 * @param string the item that is being loaded
595 * @param mixed any additional parameters
596 * @return void
597 */
598 function _ci_load_class($class, $params = NULL)
599 {
600 // Prep the class name
601 $class = strtolower(str_replace(EXT, '', $class));
602
603 // Bug fix for backward compat.
604 // Kill this at some point in the future
605 if ($class == 'unit_test')
606 {
607 $class = 'unit';
608 }
609
610 // Is this a class extension request?
611 if (substr($class, 0, 3) == 'my_')
612 {
613 $class = preg_replace("/my_(.+)/", "\\1", $class);
admin10c3f412006-10-08 07:21:12 +0000614
admin8f0a8f62006-10-07 01:17:25 +0000615 // Load the requested library from the main system/libraries folder
616 if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT))
617 {
618 include_once(BASEPATH.'libraries/'.ucfirst($class).EXT);
619 }
620
621 // Now look for a matching library
622 foreach (array(ucfirst($class), $class) as $filename)
623 {
624 if (file_exists(APPPATH.'libraries/'.$filename.EXT))
625 {
626 include_once(APPPATH.'libraries/'.$filename.EXT);
627 }
628 }
629
630 return $this->_ci_init_class($filename, 'MY_', $params);
631 }
admin10c3f412006-10-08 07:21:12 +0000632
633 // Lets search for the requested library file and load it.
634 // For backward compatibility we'll test for filenames that are
635 // both uppercase and lower.
636 foreach (array(ucfirst($class), $class) as $filename)
637 {
638 for ($i = 1; $i < 3; $i++)
admin8f0a8f62006-10-07 01:17:25 +0000639 {
admin10c3f412006-10-08 07:21:12 +0000640 $path = ($i % 2) ? APPPATH : BASEPATH;
641
642 if (file_exists($path.'libraries/'.$filename.EXT))
admin8f0a8f62006-10-07 01:17:25 +0000643 {
admin10c3f412006-10-08 07:21:12 +0000644 include_once($path.'libraries/'.$filename.EXT);
645 return $this->_ci_init_class($filename, '', $params);
admin8f0a8f62006-10-07 01:17:25 +0000646 }
647 }
648 }
649
650 // If we got this far we were unable to find the requested class
651 log_message('error', "Unable to load the requested class: ".$class);
652 show_error("Unable to load the class: ".$class);
653 }
654
655 // --------------------------------------------------------------------
656
657 /**
658 * Instantiates a class
659 *
660 * @access private
661 * @param string
662 * @param string
663 * @return null
664 */
665 function _ci_init_class($class, $prefix = '', $config = NULL)
666 {
667 // Is there an associated config file for this class?
668 if ($config == NULL)
669 {
670 if (file_exists(APPPATH.'config/'.$class.EXT))
671 {
672 include_once(APPPATH.'config/'.$class.EXT);
673 }
674 }
675
676 if ($prefix == '')
677 {
admin10c3f412006-10-08 07:21:12 +0000678 $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class;
admin8f0a8f62006-10-07 01:17:25 +0000679 }
680 else
681 {
682 $name = $prefix.$class;
683 }
684
685 $varname = ( ! isset($remap[$class])) ? $class : $remap[$class];
686 $varname = strtolower($varname);
687
688 // Instantiate the class
689 if ($config !== NULL)
690 {
691 $this->CI->$varname = new $name($config);
692 }
693 else
694 {
695 $this->CI->$varname = new $name;
696 }
697 }
adminb0dd10f2006-08-25 17:25:49 +0000698
699 // --------------------------------------------------------------------
700
701 /**
702 * Autoloader
703 *
704 * The config/autoload.php file contains an array that permits sub-systems,
admin8f0a8f62006-10-07 01:17:25 +0000705 * libraries, plugins, and helpers to be loaded automatically.
adminb0dd10f2006-08-25 17:25:49 +0000706 *
707 * @access private
708 * @param array
709 * @return void
710 */
admin8f0a8f62006-10-07 01:17:25 +0000711 function _ci_autoloader()
712 {
713 include_once(APPPATH.'config/autoload'.EXT);
714
715 if ( ! isset($autoload))
716 {
717 return FALSE;
718 }
719
720 // Load any custome config file
721 if (count($autoload['config']) > 0)
722 {
723 foreach ($autoload['config'] as $key => $val)
724 {
725 $this->CI->config->load($val);
726 }
727 }
728
729 // Load plugins, helpers, and scripts
730 foreach (array('helper', 'plugin', 'script') as $type)
731 {
732 if (isset($autoload[$type]) AND count($autoload[$type]) > 0)
733 {
734 $this->$type($autoload[$type]);
735 }
736 }
737
738 // A little tweak to remain backward compatible
739 // The $autoload['core'] item was deprecated
740 if ( ! isset($autoload['libraries']))
741 {
742 $autoload['libraries'] = $autoload['core'];
743 }
744
745 // Load libraries
746 if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0)
747 {
admin10c3f412006-10-08 07:21:12 +0000748 // Load the database driver.
admin8f0a8f62006-10-07 01:17:25 +0000749 if (in_array('database', $autoload['libraries']))
750 {
751 $this->database();
752 $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
753 }
754
admin10c3f412006-10-08 07:21:12 +0000755 // Load the model class.
admin8f0a8f62006-10-07 01:17:25 +0000756 if (in_array('model', $autoload['libraries']))
757 {
758 $this->model();
759 $autoload['libraries'] = array_diff($autoload['libraries'], array('model'));
760 }
admin10c3f412006-10-08 07:21:12 +0000761
762 // Load scaffolding
admin8f0a8f62006-10-07 01:17:25 +0000763 if (in_array('scaffolding', $autoload['libraries']))
764 {
765 $this->scaffolding();
766 $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding'));
767 }
768
admin10c3f412006-10-08 07:21:12 +0000769 // Load all other libraries
admin8f0a8f62006-10-07 01:17:25 +0000770 foreach ($autoload['libraries'] as $item)
771 {
772 $this->library($item);
773 }
774 }
775 }
776
777 // --------------------------------------------------------------------
778
779 /**
780 * Assign to Models
781 *
782 * Makes sure that anything loaded by the loader class (libraries, plugins, etc.)
783 * will be available to modles, if any exist.
784 *
785 * @access public
786 * @param object
787 * @return array
788 */
789 function _ci_assign_to_models()
adminb0dd10f2006-08-25 17:25:49 +0000790 {
admin8f0a8f62006-10-07 01:17:25 +0000791 if (count($this->models) == 0)
adminb0dd10f2006-08-25 17:25:49 +0000792 {
793 return;
794 }
admin8f0a8f62006-10-07 01:17:25 +0000795 foreach ($this->models as $model)
796 {
797 $this->CI->$model->_assign_libraries();
798 }
799 }
adminb0dd10f2006-08-25 17:25:49 +0000800
801 // --------------------------------------------------------------------
802
803 /**
804 * Object to Array
805 *
806 * Takes an object as input and convers the class variables to array key/vals
807 *
808 * @access public
809 * @param object
810 * @return array
811 */
812 function _ci_object_to_array($object)
813 {
admin2e5872a2006-09-06 02:32:55 +0000814 return (is_object($object)) ? get_object_vars($object) : $object;
adminb0dd10f2006-08-25 17:25:49 +0000815 }
admin8f0a8f62006-10-07 01:17:25 +0000816
adminb0dd10f2006-08-25 17:25:49 +0000817
818}
adminb0dd10f2006-08-25 17:25:49 +0000819?>