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