blob: 638c7932c94075bd94bafb85233431b251f57764 [file] [log] [blame]
Andrey Andreevd7297352012-01-07 22:53:14 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreevd7297352012-01-07 22:53:14 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreevd7297352012-01-07 22:53:14 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
Derek Allard2067d1a2008-11-13 22:59:24 +000018 *
19 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * Loader Class
30 *
31 * Loads views and files
32 *
33 * @package CodeIgniter
34 * @subpackage Libraries
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @category Loader
Andrey Andreev92ebfb62012-05-17 12:49:24 +030036 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000037 * @link http://codeigniter.com/user_guide/libraries/loader.html
38 */
39class CI_Loader {
40
41 // All these are set automatically. Don't mess with them.
David Behlercda768a2011-08-14 23:52:48 +020042 /**
43 * Nesting level of the output buffering mechanism
44 *
45 * @var int
David Behlercda768a2011-08-14 23:52:48 +020046 */
Greg Aker0c9ee4a2011-04-20 09:40:17 -050047 protected $_ci_ob_level;
Andrey Andreev92ebfb62012-05-17 12:49:24 +030048
David Behlercda768a2011-08-14 23:52:48 +020049 /**
50 * List of paths to load views from
51 *
52 * @var array
David Behlercda768a2011-08-14 23:52:48 +020053 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040054 protected $_ci_view_paths = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030055
David Behlercda768a2011-08-14 23:52:48 +020056 /**
57 * List of paths to load libraries from
58 *
59 * @var array
David Behlercda768a2011-08-14 23:52:48 +020060 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040061 protected $_ci_library_paths = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030062
David Behlercda768a2011-08-14 23:52:48 +020063 /**
64 * List of paths to load models from
65 *
66 * @var array
David Behlercda768a2011-08-14 23:52:48 +020067 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040068 protected $_ci_model_paths = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030069
David Behlercda768a2011-08-14 23:52:48 +020070 /**
71 * List of paths to load helpers from
72 *
73 * @var array
David Behlercda768a2011-08-14 23:52:48 +020074 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040075 protected $_ci_helper_paths = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030076
David Behlercda768a2011-08-14 23:52:48 +020077 /**
dchill4260d100f2012-08-29 12:58:26 -040078 * Path to autoloader config file
79 * This lets us override it in unit testing
80 *
81 * @var string
82 */
83 protected $_ci_autoloader_path = APPPATH;
84
85 /**
David Behlercda768a2011-08-14 23:52:48 +020086 * List of loaded base classes
David Behlercda768a2011-08-14 23:52:48 +020087 *
88 * @var array
David Behlercda768a2011-08-14 23:52:48 +020089 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040090 protected $_base_classes = array(); // Set by the controller class
Andrey Andreev92ebfb62012-05-17 12:49:24 +030091
David Behlercda768a2011-08-14 23:52:48 +020092 /**
93 * List of cached variables
94 *
95 * @var array
David Behlercda768a2011-08-14 23:52:48 +020096 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040097 protected $_ci_cached_vars = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030098
David Behlercda768a2011-08-14 23:52:48 +020099 /**
100 * List of loaded classes
101 *
102 * @var array
David Behlercda768a2011-08-14 23:52:48 +0200103 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -0400104 protected $_ci_classes = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300105
David Behlercda768a2011-08-14 23:52:48 +0200106 /**
107 * List of loaded files
108 *
109 * @var array
David Behlercda768a2011-08-14 23:52:48 +0200110 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -0400111 protected $_ci_loaded_files = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300112
David Behlercda768a2011-08-14 23:52:48 +0200113 /**
114 * List of loaded models
115 *
116 * @var array
David Behlercda768a2011-08-14 23:52:48 +0200117 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -0400118 protected $_ci_models = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300119
David Behlercda768a2011-08-14 23:52:48 +0200120 /**
121 * List of loaded helpers
122 *
123 * @var array
David Behlercda768a2011-08-14 23:52:48 +0200124 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -0400125 protected $_ci_helpers = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300126
David Behlercda768a2011-08-14 23:52:48 +0200127 /**
128 * List of class name mappings
129 *
130 * @var array
David Behlercda768a2011-08-14 23:52:48 +0200131 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -0400132 protected $_ci_varmap = array(
Timothy Warren40403d22012-04-19 16:38:50 -0400133 'unit_test' => 'unit',
134 'user_agent' => 'agent'
135 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000136
137 /**
138 * Constructor
139 *
140 * Sets the path to the view files and gets the initial output buffering level
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300141 *
142 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 */
Greg Akerf5c84022011-04-19 17:13:03 -0500144 public function __construct()
Barry Mienydd671972010-10-04 16:33:58 +0200145 {
Derek Jones37f4b9c2011-07-01 17:56:50 -0500146 $this->_ci_ob_level = ob_get_level();
Derek Jones32bf1862010-03-02 13:46:07 -0600147 $this->_ci_library_paths = array(APPPATH, BASEPATH);
148 $this->_ci_helper_paths = array(APPPATH, BASEPATH);
149 $this->_ci_model_paths = array(APPPATH);
Joe Cianflone8eef9c72011-08-21 10:39:06 -0400150 $this->_ci_view_paths = array(VIEWPATH => TRUE);
David Behlercda768a2011-08-14 23:52:48 +0200151
Andrey Andreevd7297352012-01-07 22:53:14 +0200152 log_message('debug', 'Loader Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +0000153 }
Barry Mienydd671972010-10-04 16:33:58 +0200154
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 // --------------------------------------------------------------------
David Behlercda768a2011-08-14 23:52:48 +0200156
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500157 /**
Shane Pearson6adfe632011-08-10 16:42:53 -0500158 * Initialize the Loader
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500159 *
160 * This method is called once in CI_Controller.
161 *
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500162 * @return object
163 */
Shane Pearson6adfe632011-08-10 16:42:53 -0500164 public function initialize()
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500165 {
Shane Pearson6adfe632011-08-10 16:42:53 -0500166 $this->_ci_classes = array();
167 $this->_ci_loaded_files = array();
168 $this->_ci_models = array();
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500169 $this->_base_classes =& is_loaded();
Shane Pearson6adfe632011-08-10 16:42:53 -0500170
171 $this->_ci_autoloader();
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500172 return $this;
173 }
174
175 // --------------------------------------------------------------------
176
177 /**
178 * Is Loaded
179 *
180 * A utility function to test if a class is in the self::$_ci_classes array.
181 * This function returns the object name if the class tested for is loaded,
182 * and returns FALSE if it isn't.
183 *
184 * It is mainly used in the form_helper -> _get_validation_object()
185 *
186 * @param string class being checked for
187 * @return mixed class object name on the CI SuperObject or FALSE
188 */
189 public function is_loaded($class)
190 {
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300191 return isset($this->_ci_classes[$class]) ? $this->_ci_classes[$class] : FALSE;
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500192 }
193
194 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200195
Derek Allard2067d1a2008-11-13 22:59:24 +0000196 /**
197 * Class Loader
198 *
199 * This function lets users load and instantiate classes.
200 * It is designed to be called from a user's app controllers.
201 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 * @param string the name of the class
203 * @param mixed the optional parameters
204 * @param string an optional object name
205 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200206 */
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500207 public function library($library = '', $params = NULL, $object_name = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 {
Greg Akerce433962010-10-12 09:29:35 -0500209 if (is_array($library))
210 {
Phil Sturgeon08b51692011-04-03 18:05:42 +0100211 foreach ($library as $class)
Greg Akerce433962010-10-12 09:29:35 -0500212 {
Kellas Reeves3c6e4852011-02-09 11:57:56 -0600213 $this->library($class, $params);
Greg Akerce433962010-10-12 09:29:35 -0500214 }
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000215
Greg Akerce433962010-10-12 09:29:35 -0500216 return;
217 }
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000218
Alex Bilbieed944a32012-06-02 11:07:47 +0100219 if ($library === '' OR isset($this->_base_classes[$library]))
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 {
221 return FALSE;
222 }
223
Derek Jones32bf1862010-03-02 13:46:07 -0600224 if ( ! is_null($params) && ! is_array($params))
Derek Allard2067d1a2008-11-13 22:59:24 +0000225 {
226 $params = NULL;
227 }
228
Kellas Reeves3c6e4852011-02-09 11:57:56 -0600229 $this->_ci_load_class($library, $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000230 }
231
232 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200233
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 /**
235 * Model Loader
236 *
237 * This function lets users load and instantiate models.
238 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 * @param string the name of the class
240 * @param string name for the model
241 * @param bool database connection
242 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200243 */
Greg Akerf5c84022011-04-19 17:13:03 -0500244 public function model($model, $name = '', $db_conn = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200245 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 if (is_array($model))
247 {
Joel Limberg3cf174b2012-07-13 20:49:57 +0300248 foreach ($model as $class)
Derek Allard2067d1a2008-11-13 22:59:24 +0000249 {
Joel Limberg3cf174b2012-07-13 20:49:57 +0300250 $this->model($class);
Derek Allard2067d1a2008-11-13 22:59:24 +0000251 }
252 return;
253 }
254
Alex Bilbieed944a32012-06-02 11:07:47 +0100255 if ($model === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000256 {
257 return;
258 }
Barry Mienydd671972010-10-04 16:33:58 +0200259
Derek Jones32bf1862010-03-02 13:46:07 -0600260 $path = '';
Barry Mienydd671972010-10-04 16:33:58 +0200261
Derek Allard2067d1a2008-11-13 22:59:24 +0000262 // Is the model in a sub-folder? If so, parse out the filename and path.
Derek Jones32bf1862010-03-02 13:46:07 -0600263 if (($last_slash = strrpos($model, '/')) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000264 {
Derek Jones32bf1862010-03-02 13:46:07 -0600265 // The path is in front of the last slash
Andrey Andreevd47baab2012-01-09 16:56:46 +0200266 $path = substr($model, 0, ++$last_slash);
Derek Jones32bf1862010-03-02 13:46:07 -0600267
268 // And the model name behind it
Andrey Andreevd47baab2012-01-09 16:56:46 +0200269 $model = substr($model, $last_slash);
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 }
Barry Mienydd671972010-10-04 16:33:58 +0200271
Phil Sturgeon10d78f62012-06-04 14:41:53 -0500272 if (empty($name))
Derek Allard2067d1a2008-11-13 22:59:24 +0000273 {
274 $name = $model;
275 }
Barry Mienydd671972010-10-04 16:33:58 +0200276
Derek Allard2067d1a2008-11-13 22:59:24 +0000277 if (in_array($name, $this->_ci_models, TRUE))
278 {
279 return;
280 }
Barry Mienydd671972010-10-04 16:33:58 +0200281
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 $CI =& get_instance();
283 if (isset($CI->$name))
284 {
285 show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
286 }
Barry Mienydd671972010-10-04 16:33:58 +0200287
Derek Allard2067d1a2008-11-13 22:59:24 +0000288 $model = strtolower($model);
Derek Allard2067d1a2008-11-13 22:59:24 +0000289
Derek Jones32bf1862010-03-02 13:46:07 -0600290 foreach ($this->_ci_model_paths as $mod_path)
291 {
Greg Aker3a746652011-04-19 10:59:47 -0500292 if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
Derek Jones32bf1862010-03-02 13:46:07 -0600293 {
294 continue;
295 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000296
Andrey Andreev94af3552012-03-26 23:10:42 +0300297 if ($db_conn !== FALSE && ! class_exists('CI_DB'))
Derek Jones32bf1862010-03-02 13:46:07 -0600298 {
299 if ($db_conn === TRUE)
Pascal Kriete287781e2010-11-10 15:43:49 -0500300 {
Derek Jones32bf1862010-03-02 13:46:07 -0600301 $db_conn = '';
Pascal Kriete287781e2010-11-10 15:43:49 -0500302 }
Derek Jones32bf1862010-03-02 13:46:07 -0600303
304 $CI->load->database($db_conn, FALSE, TRUE);
305 }
306
Greg Akerbce13482010-10-11 15:37:16 -0500307 if ( ! class_exists('CI_Model'))
Derek Jones32bf1862010-03-02 13:46:07 -0600308 {
309 load_class('Model', 'core');
310 }
311
Greg Aker3a746652011-04-19 10:59:47 -0500312 require_once($mod_path.'models/'.$path.$model.'.php');
Derek Jones32bf1862010-03-02 13:46:07 -0600313
314 $model = ucfirst($model);
Derek Jones32bf1862010-03-02 13:46:07 -0600315 $CI->$name = new $model();
Derek Jones32bf1862010-03-02 13:46:07 -0600316 $this->_ci_models[] = $name;
317 return;
318 }
Barry Mienydd671972010-10-04 16:33:58 +0200319
Derek Jones32bf1862010-03-02 13:46:07 -0600320 // couldn't find the model
321 show_error('Unable to locate the model you have specified: '.$model);
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 }
Barry Mienydd671972010-10-04 16:33:58 +0200323
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200325
Derek Allard2067d1a2008-11-13 22:59:24 +0000326 /**
327 * Database Loader
328 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000329 * @param string the DB credentials
330 * @param bool whether to return the DB object
Jamie Rumbelow7efad202012-02-19 12:37:00 +0000331 * @param bool whether to enable query builder (this allows us to override the config setting)
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 * @return object
Barry Mienydd671972010-10-04 16:33:58 +0200333 */
Jamie Rumbelow7efad202012-02-19 12:37:00 +0000334 public function database($params = '', $return = FALSE, $query_builder = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000335 {
336 // Grab the super object
337 $CI =& get_instance();
Barry Mienydd671972010-10-04 16:33:58 +0200338
Derek Allard2067d1a2008-11-13 22:59:24 +0000339 // Do we even need to load the database class?
Alex Bilbieed944a32012-06-02 11:07:47 +0100340 if (class_exists('CI_DB') && $return === FALSE && $query_builder === NULL && isset($CI->db) && is_object($CI->db))
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 {
342 return FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200343 }
344
Greg Aker3a746652011-04-19 10:59:47 -0500345 require_once(BASEPATH.'database/DB.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000346
347 if ($return === TRUE)
348 {
Jamie Rumbelow7efad202012-02-19 12:37:00 +0000349 return DB($params, $query_builder);
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 }
Barry Mienydd671972010-10-04 16:33:58 +0200351
Andrey Andreevd7297352012-01-07 22:53:14 +0200352 // Initialize the db variable. Needed to prevent
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 // reference errors with some configurations
354 $CI->db = '';
Barry Mienydd671972010-10-04 16:33:58 +0200355
Derek Allard2067d1a2008-11-13 22:59:24 +0000356 // Load the DB class
Jamie Rumbelow7efad202012-02-19 12:37:00 +0000357 $CI->db =& DB($params, $query_builder);
Derek Allard2067d1a2008-11-13 22:59:24 +0000358 }
Barry Mienydd671972010-10-04 16:33:58 +0200359
Derek Allard2067d1a2008-11-13 22:59:24 +0000360 // --------------------------------------------------------------------
361
362 /**
363 * Load the Utilities Class
364 *
Barry Mienydd671972010-10-04 16:33:58 +0200365 * @return string
366 */
Greg Akerf5c84022011-04-19 17:13:03 -0500367 public function dbutil()
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 {
369 if ( ! class_exists('CI_DB'))
370 {
371 $this->database();
372 }
Barry Mienydd671972010-10-04 16:33:58 +0200373
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 $CI =& get_instance();
375
376 // for backwards compatibility, load dbforge so we can extend dbutils off it
377 // this use is deprecated and strongly discouraged
378 $CI->load->dbforge();
Barry Mienydd671972010-10-04 16:33:58 +0200379
Greg Aker3a746652011-04-19 10:59:47 -0500380 require_once(BASEPATH.'database/DB_utility.php');
381 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000382 $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
383
Pascal Kriete58560022010-11-10 16:01:20 -0500384 $CI->dbutil = new $class();
Derek Allard2067d1a2008-11-13 22:59:24 +0000385 }
Barry Mienydd671972010-10-04 16:33:58 +0200386
Derek Allard2067d1a2008-11-13 22:59:24 +0000387 // --------------------------------------------------------------------
388
389 /**
390 * Load the Database Forge Class
391 *
Barry Mienydd671972010-10-04 16:33:58 +0200392 * @return string
393 */
Greg Akerf5c84022011-04-19 17:13:03 -0500394 public function dbforge()
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 {
396 if ( ! class_exists('CI_DB'))
397 {
398 $this->database();
399 }
Barry Mienydd671972010-10-04 16:33:58 +0200400
Derek Allard2067d1a2008-11-13 22:59:24 +0000401 $CI =& get_instance();
Barry Mienydd671972010-10-04 16:33:58 +0200402
Greg Aker3a746652011-04-19 10:59:47 -0500403 require_once(BASEPATH.'database/DB_forge.php');
404 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000405 $class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
406
407 $CI->dbforge = new $class();
Derek Allard2067d1a2008-11-13 22:59:24 +0000408 }
Barry Mienydd671972010-10-04 16:33:58 +0200409
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200411
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 /**
413 * Load View
414 *
Andrey Andreev94af3552012-03-26 23:10:42 +0300415 * This function is used to load a "view" file. It has three parameters:
Derek Allard2067d1a2008-11-13 22:59:24 +0000416 *
417 * 1. The name of the "view" file to be included.
418 * 2. An associative array of data to be extracted for use in the view.
Andrey Andreev94af3552012-03-26 23:10:42 +0300419 * 3. TRUE/FALSE - whether to return the data or load it. In
dchill425628ba02012-08-08 12:05:45 -0400420 * some cases it's advantageous to be able to return data so that
421 * a developer can process it in some way.
Derek Allard2067d1a2008-11-13 22:59:24 +0000422 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000423 * @param string
424 * @param array
425 * @param bool
426 * @return void
427 */
Greg Akerf5c84022011-04-19 17:13:03 -0500428 public function view($view, $vars = array(), $return = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000429 {
430 return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
431 }
Barry Mienydd671972010-10-04 16:33:58 +0200432
Derek Allard2067d1a2008-11-13 22:59:24 +0000433 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200434
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 /**
436 * Load File
437 *
438 * This is a generic file loader
439 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 * @param string
441 * @param bool
442 * @return string
443 */
Greg Akerf5c84022011-04-19 17:13:03 -0500444 public function file($path, $return = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 {
446 return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return));
447 }
Barry Mienydd671972010-10-04 16:33:58 +0200448
Derek Allard2067d1a2008-11-13 22:59:24 +0000449 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200450
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 /**
452 * Set Variables
453 *
454 * Once variables are set they become available within
455 * the controller class and its "view" files.
456 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000457 * @param array
David Behlercda768a2011-08-14 23:52:48 +0200458 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +0000459 * @return void
460 */
Greg Akerf5c84022011-04-19 17:13:03 -0500461 public function vars($vars = array(), $val = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000462 {
Alex Bilbieed944a32012-06-02 11:07:47 +0100463 if ($val !== '' && is_string($vars))
Derek Allard2067d1a2008-11-13 22:59:24 +0000464 {
465 $vars = array($vars => $val);
466 }
Barry Mienydd671972010-10-04 16:33:58 +0200467
Derek Allard2067d1a2008-11-13 22:59:24 +0000468 $vars = $this->_ci_object_to_array($vars);
Barry Mienydd671972010-10-04 16:33:58 +0200469
Andrey Andreev94af3552012-03-26 23:10:42 +0300470 if (is_array($vars) && count($vars) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000471 {
472 foreach ($vars as $key => $val)
473 {
474 $this->_ci_cached_vars[$key] = $val;
475 }
476 }
477 }
Barry Mienydd671972010-10-04 16:33:58 +0200478
Derek Allard2067d1a2008-11-13 22:59:24 +0000479 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200480
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 /**
Phil Sturgeon8731f642011-07-22 16:11:34 -0600482 * Get Variable
483 *
484 * Check if a variable is set and retrieve it.
485 *
486 * @param array
487 * @return void
488 */
489 public function get_var($key)
490 {
491 return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL;
492 }
493
494 // --------------------------------------------------------------------
495
496 /**
Shane Pearson81dd2232011-11-18 20:49:35 -0600497 * Get Variables
498 *
499 * Retrieve all loaded variables
500 *
501 * @return array
502 */
503 public function get_vars()
504 {
505 return $this->_ci_cached_vars;
506 }
507
508 // --------------------------------------------------------------------
509
510 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000511 * Load Helper
512 *
513 * This function loads the specified helper file.
514 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000515 * @param mixed
516 * @return void
517 */
Greg Akerf5c84022011-04-19 17:13:03 -0500518 public function helper($helpers = array())
Barry Mienydd671972010-10-04 16:33:58 +0200519 {
Derek Jones32bf1862010-03-02 13:46:07 -0600520 foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
Barry Mienydd671972010-10-04 16:33:58 +0200521 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000522 if (isset($this->_ci_helpers[$helper]))
523 {
524 continue;
525 }
Derek Jones32bf1862010-03-02 13:46:07 -0600526
Greg Aker3a746652011-04-19 10:59:47 -0500527 $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.'.php';
Derek Allard2067d1a2008-11-13 22:59:24 +0000528
Barry Mienydd671972010-10-04 16:33:58 +0200529 // Is this a helper extension request?
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 if (file_exists($ext_helper))
531 {
Greg Aker3a746652011-04-19 10:59:47 -0500532 $base_helper = BASEPATH.'helpers/'.$helper.'.php';
Barry Mienydd671972010-10-04 16:33:58 +0200533
Derek Allard2067d1a2008-11-13 22:59:24 +0000534 if ( ! file_exists($base_helper))
535 {
Greg Aker3a746652011-04-19 10:59:47 -0500536 show_error('Unable to load the requested file: helpers/'.$helper.'.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000537 }
Barry Mienydd671972010-10-04 16:33:58 +0200538
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 include_once($ext_helper);
540 include_once($base_helper);
Barry Mienydd671972010-10-04 16:33:58 +0200541
Derek Jones32bf1862010-03-02 13:46:07 -0600542 $this->_ci_helpers[$helper] = TRUE;
543 log_message('debug', 'Helper loaded: '.$helper);
544 continue;
Derek Allard2067d1a2008-11-13 22:59:24 +0000545 }
Barry Mienydd671972010-10-04 16:33:58 +0200546
Derek Jones32bf1862010-03-02 13:46:07 -0600547 // Try to load the helper
548 foreach ($this->_ci_helper_paths as $path)
549 {
Greg Aker3a746652011-04-19 10:59:47 -0500550 if (file_exists($path.'helpers/'.$helper.'.php'))
Barry Mienydd671972010-10-04 16:33:58 +0200551 {
Greg Aker3a746652011-04-19 10:59:47 -0500552 include_once($path.'helpers/'.$helper.'.php');
Derek Jones32bf1862010-03-02 13:46:07 -0600553
554 $this->_ci_helpers[$helper] = TRUE;
Barry Mienydd671972010-10-04 16:33:58 +0200555 log_message('debug', 'Helper loaded: '.$helper);
Derek Jones32bf1862010-03-02 13:46:07 -0600556 break;
Derek Allard2067d1a2008-11-13 22:59:24 +0000557 }
558 }
559
Derek Jones32bf1862010-03-02 13:46:07 -0600560 // unable to load the helper
561 if ( ! isset($this->_ci_helpers[$helper]))
562 {
Greg Aker3a746652011-04-19 10:59:47 -0500563 show_error('Unable to load the requested file: helpers/'.$helper.'.php');
Derek Jones32bf1862010-03-02 13:46:07 -0600564 }
Barry Mienydd671972010-10-04 16:33:58 +0200565 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000566 }
Barry Mienydd671972010-10-04 16:33:58 +0200567
Derek Allard2067d1a2008-11-13 22:59:24 +0000568 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200569
Derek Allard2067d1a2008-11-13 22:59:24 +0000570 /**
571 * Load Helpers
572 *
573 * This is simply an alias to the above function in case the
574 * user has written the plural form of this function.
575 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000576 * @param array
577 * @return void
578 */
Greg Akerf5c84022011-04-19 17:13:03 -0500579 public function helpers($helpers = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000580 {
581 $this->helper($helpers);
582 }
Barry Mienydd671972010-10-04 16:33:58 +0200583
Derek Allard2067d1a2008-11-13 22:59:24 +0000584 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200585
Derek Allard2067d1a2008-11-13 22:59:24 +0000586 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000587 * Loads a language file
588 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000589 * @param array
590 * @param string
591 * @return void
592 */
Greg Akerf5c84022011-04-19 17:13:03 -0500593 public function language($file = array(), $lang = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000594 {
595 $CI =& get_instance();
596
597 if ( ! is_array($file))
598 {
599 $file = array($file);
600 }
601
602 foreach ($file as $langfile)
Barry Mienydd671972010-10-04 16:33:58 +0200603 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000604 $CI->lang->load($langfile, $lang);
605 }
606 }
Barry Mienydd671972010-10-04 16:33:58 +0200607
Derek Allard2067d1a2008-11-13 22:59:24 +0000608 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200609
Derek Allard2067d1a2008-11-13 22:59:24 +0000610 /**
611 * Loads a config file
612 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000613 * @param string
David Behlercda768a2011-08-14 23:52:48 +0200614 * @param bool
615 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000616 * @return void
617 */
Greg Akerf5c84022011-04-19 17:13:03 -0500618 public function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200619 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000620 $CI =& get_instance();
621 $CI->config->load($file, $use_sections, $fail_gracefully);
622 }
623
624 // --------------------------------------------------------------------
Derek Jones32bf1862010-03-02 13:46:07 -0600625
Derek Allard2067d1a2008-11-13 22:59:24 +0000626 /**
Derek Jones8dca0412010-03-05 13:01:44 -0600627 * Driver
628 *
629 * Loads a driver library
630 *
Christopher Guiney9929d6f2012-03-09 19:53:24 -0800631 * @param mixed the name of the class or array of classes
Derek Jones8dca0412010-03-05 13:01:44 -0600632 * @param mixed the optional parameters
633 * @param string an optional object name
634 * @return void
635 */
Greg Akerf5c84022011-04-19 17:13:03 -0500636 public function driver($library = '', $params = NULL, $object_name = NULL)
Derek Jones8dca0412010-03-05 13:01:44 -0600637 {
Christopher Guineyb54d3552012-03-10 08:38:10 -0800638 if (is_array($library))
Christopher Guiney9929d6f2012-03-09 19:53:24 -0800639 {
Christopher Guineyb54d3552012-03-10 08:38:10 -0800640 foreach ($library as $driver)
Christopher Guiney9929d6f2012-03-09 19:53:24 -0800641 {
642 $this->driver($driver);
643 }
dchill420fc3be52012-08-27 20:54:23 -0400644 return;
Christopher Guiney9929d6f2012-03-09 19:53:24 -0800645 }
646
Alex Bilbieed944a32012-06-02 11:07:47 +0100647 if ($library === '')
Tom Klingenberg6a15b2d2011-10-07 20:03:30 +0200648 {
649 return FALSE;
650 }
651
Derek Jonesd5e0cb52010-03-09 20:20:46 -0600652 // We can save the loader some time since Drivers will *always* be in a subfolder,
653 // and typically identically named to the library
654 if ( ! strpos($library, '/'))
655 {
Greg Akerd25e66a2010-03-28 01:07:09 -0500656 $library = ucfirst($library).'/'.$library;
Derek Jones8dca0412010-03-05 13:01:44 -0600657 }
Barry Mienydd671972010-10-04 16:33:58 +0200658
Derek Jones8dca0412010-03-05 13:01:44 -0600659 return $this->library($library, $params, $object_name);
660 }
661
662 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200663
Derek Jones8dca0412010-03-05 13:01:44 -0600664 /**
Derek Jones32bf1862010-03-02 13:46:07 -0600665 * Add Package Path
Derek Allard2067d1a2008-11-13 22:59:24 +0000666 *
Derek Jones32bf1862010-03-02 13:46:07 -0600667 * Prepends a parent path to the library, model, helper, and config path arrays
Derek Allard2067d1a2008-11-13 22:59:24 +0000668 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000669 * @param string
Andrey Andreev94af3552012-03-26 23:10:42 +0300670 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000671 * @return void
Derek Jones32bf1862010-03-02 13:46:07 -0600672 */
Andrey Andreevcce91802012-06-12 13:25:31 +0300673 public function add_package_path($path, $view_cascade = TRUE)
Derek Jones32bf1862010-03-02 13:46:07 -0600674 {
Pascal Kriete6b6c2742010-11-09 13:12:22 -0500675 $path = rtrim($path, '/').'/';
David Behlercda768a2011-08-14 23:52:48 +0200676
Derek Jones32bf1862010-03-02 13:46:07 -0600677 array_unshift($this->_ci_library_paths, $path);
678 array_unshift($this->_ci_model_paths, $path);
679 array_unshift($this->_ci_helper_paths, $path);
Barry Mienydd671972010-10-04 16:33:58 +0200680
Greg Akerf5c84022011-04-19 17:13:03 -0500681 $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths;
682
Derek Jones32bf1862010-03-02 13:46:07 -0600683 // Add config file path
684 $config =& $this->_ci_get_component('config');
Korri3684d342012-04-17 00:35:08 -0400685 array_push($config->_config_paths, $path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000686 }
687
688 // --------------------------------------------------------------------
Derek Jones32bf1862010-03-02 13:46:07 -0600689
690 /**
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000691 * Get Package Paths
692 *
693 * Return a list of all package paths, by default it will ignore BASEPATH.
694 *
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000695 * @param string
696 * @return void
697 */
Greg Akerf5c84022011-04-19 17:13:03 -0500698 public function get_package_paths($include_base = FALSE)
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000699 {
700 return $include_base === TRUE ? $this->_ci_library_paths : $this->_ci_model_paths;
701 }
702
703 // --------------------------------------------------------------------
704
705 /**
Derek Jones32bf1862010-03-02 13:46:07 -0600706 * Remove Package Path
707 *
708 * Remove a path from the library, model, and helper path arrays if it exists
709 * If no path is provided, the most recently added path is removed.
710 *
Andrey Andreev94af3552012-03-26 23:10:42 +0300711 * @param string
David Behlercda768a2011-08-14 23:52:48 +0200712 * @param bool
Andrey Andreev94af3552012-03-26 23:10:42 +0300713 * @return void
Derek Jones32bf1862010-03-02 13:46:07 -0600714 */
Greg Akerf5c84022011-04-19 17:13:03 -0500715 public function remove_package_path($path = '', $remove_config_path = TRUE)
Derek Jones32bf1862010-03-02 13:46:07 -0600716 {
717 $config =& $this->_ci_get_component('config');
Barry Mienydd671972010-10-04 16:33:58 +0200718
Alex Bilbieed944a32012-06-02 11:07:47 +0100719 if ($path === '')
Derek Jones32bf1862010-03-02 13:46:07 -0600720 {
Andrey Andreevd7297352012-01-07 22:53:14 +0200721 array_shift($this->_ci_library_paths);
722 array_shift($this->_ci_model_paths);
723 array_shift($this->_ci_helper_paths);
724 array_shift($this->_ci_view_paths);
Korri3684d342012-04-17 00:35:08 -0400725 array_pop($config->_config_paths);
Derek Jones32bf1862010-03-02 13:46:07 -0600726 }
727 else
728 {
Pascal Kriete6b6c2742010-11-09 13:12:22 -0500729 $path = rtrim($path, '/').'/';
Derek Jones32bf1862010-03-02 13:46:07 -0600730 foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var)
731 {
732 if (($key = array_search($path, $this->{$var})) !== FALSE)
733 {
734 unset($this->{$var}[$key]);
735 }
736 }
David Behlercda768a2011-08-14 23:52:48 +0200737
Greg Akerf5c84022011-04-19 17:13:03 -0500738 if (isset($this->_ci_view_paths[$path.'views/']))
739 {
740 unset($this->_ci_view_paths[$path.'views/']);
741 }
Barry Mienydd671972010-10-04 16:33:58 +0200742
Derek Jones32bf1862010-03-02 13:46:07 -0600743 if (($key = array_search($path, $config->_config_paths)) !== FALSE)
744 {
745 unset($config->_config_paths[$key]);
746 }
747 }
Barry Mienydd671972010-10-04 16:33:58 +0200748
Derek Jones32bf1862010-03-02 13:46:07 -0600749 // make sure the application default paths are still in the array
750 $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH)));
751 $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH)));
752 $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH)));
Greg Akerf5c84022011-04-19 17:13:03 -0500753 $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE));
Derek Jones32bf1862010-03-02 13:46:07 -0600754 $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH)));
755 }
756
757 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200758
Derek Allard2067d1a2008-11-13 22:59:24 +0000759 /**
760 * Loader
761 *
762 * This function is used to load views and files.
763 * Variables are prefixed with _ci_ to avoid symbol collision with
764 * variables made available to view files
765 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000766 * @param array
767 * @return void
768 */
Greg Akerf5c84022011-04-19 17:13:03 -0500769 protected function _ci_load($_ci_data)
Derek Allard2067d1a2008-11-13 22:59:24 +0000770 {
771 // Set the default data variables
772 foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val)
773 {
Andrey Andreev94af3552012-03-26 23:10:42 +0300774 $$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000775 }
David Behlercda768a2011-08-14 23:52:48 +0200776
Greg Akerf5c84022011-04-19 17:13:03 -0500777 $file_exists = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000778
779 // Set the path to the requested file
Alex Bilbie40bd2a72012-06-02 16:04:15 +0100780 if (is_string($_ci_path) && $_ci_path !== '')
Greg Aker8807be32011-04-21 13:06:15 -0500781 {
782 $_ci_x = explode('/', $_ci_path);
783 $_ci_file = end($_ci_x);
784 }
785 else
Derek Allard2067d1a2008-11-13 22:59:24 +0000786 {
787 $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
Alex Bilbieed944a32012-06-02 11:07:47 +0100788 $_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view;
Greg Akerf5c84022011-04-19 17:13:03 -0500789
790 foreach ($this->_ci_view_paths as $view_file => $cascade)
791 {
792 if (file_exists($view_file.$_ci_file))
793 {
794 $_ci_path = $view_file.$_ci_file;
795 $file_exists = TRUE;
796 break;
797 }
David Behlercda768a2011-08-14 23:52:48 +0200798
Greg Akerf5c84022011-04-19 17:13:03 -0500799 if ( ! $cascade)
800 {
801 break;
David Behlercda768a2011-08-14 23:52:48 +0200802 }
Greg Akerf5c84022011-04-19 17:13:03 -0500803 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000804 }
Barry Mienydd671972010-10-04 16:33:58 +0200805
Greg Akerf5c84022011-04-19 17:13:03 -0500806 if ( ! $file_exists && ! file_exists($_ci_path))
Derek Allard2067d1a2008-11-13 22:59:24 +0000807 {
808 show_error('Unable to load the requested file: '.$_ci_file);
809 }
Barry Mienydd671972010-10-04 16:33:58 +0200810
Derek Allard2067d1a2008-11-13 22:59:24 +0000811 // This allows anything loaded using $this->load (views, files, etc.)
812 // to become accessible from within the Controller and Model functions.
Pascal Kriete89ace432010-11-10 15:49:10 -0500813 $_ci_CI =& get_instance();
814 foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
Derek Allard2067d1a2008-11-13 22:59:24 +0000815 {
Pascal Kriete89ace432010-11-10 15:49:10 -0500816 if ( ! isset($this->$_ci_key))
Derek Allard2067d1a2008-11-13 22:59:24 +0000817 {
Pascal Kriete89ace432010-11-10 15:49:10 -0500818 $this->$_ci_key =& $_ci_CI->$_ci_key;
Derek Allard2067d1a2008-11-13 22:59:24 +0000819 }
820 }
821
822 /*
823 * Extract and cache variables
824 *
vlakoff02506182012-07-03 07:28:50 +0200825 * You can either set variables using the dedicated $this->load->vars()
Derek Allard2067d1a2008-11-13 22:59:24 +0000826 * function or via the second parameter of this function. We'll merge
827 * the two types and cache them so that views that are embedded within
828 * other views can have access to these variables.
Barry Mienydd671972010-10-04 16:33:58 +0200829 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000830 if (is_array($_ci_vars))
831 {
832 $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
833 }
834 extract($this->_ci_cached_vars);
Barry Mienydd671972010-10-04 16:33:58 +0200835
Derek Allard2067d1a2008-11-13 22:59:24 +0000836 /*
837 * Buffer the output
838 *
839 * We buffer the output for two reasons:
840 * 1. Speed. You get a significant speed boost.
Andrey Andreevd7297352012-01-07 22:53:14 +0200841 * 2. So that the final rendered template can be post-processed by
dchill425628ba02012-08-08 12:05:45 -0400842 * the output class. Why do we need post processing? For one thing,
843 * in order to show the elapsed page load time. Unless we can
844 * intercept the content right before it's sent to the browser and
845 * then stop the timer it won't be accurate.
Derek Allard2067d1a2008-11-13 22:59:24 +0000846 */
847 ob_start();
Barry Mienydd671972010-10-04 16:33:58 +0200848
Derek Allard2067d1a2008-11-13 22:59:24 +0000849 // If the PHP installation does not support short tags we'll
850 // do a little string replacement, changing the short tags
851 // to standard PHP echo statements.
Alex Bilbieed944a32012-06-02 11:07:47 +0100852 if ( ! is_php('5.4') && (bool) @ini_get('short_open_tag') === FALSE && config_item('rewrite_short_tags') === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000853 {
Andrey Andreevd47baab2012-01-09 16:56:46 +0200854 echo eval('?>'.preg_replace('/;*\s*\?>/', '; ?>', str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000855 }
856 else
857 {
858 include($_ci_path); // include() vs include_once() allows for multiple views with the same name
859 }
Barry Mienydd671972010-10-04 16:33:58 +0200860
Derek Allard2067d1a2008-11-13 22:59:24 +0000861 log_message('debug', 'File loaded: '.$_ci_path);
Barry Mienydd671972010-10-04 16:33:58 +0200862
Derek Allard2067d1a2008-11-13 22:59:24 +0000863 // Return the file data if requested
864 if ($_ci_return === TRUE)
Barry Mienydd671972010-10-04 16:33:58 +0200865 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000866 $buffer = ob_get_contents();
867 @ob_end_clean();
868 return $buffer;
869 }
870
871 /*
872 * Flush the buffer... or buff the flusher?
873 *
874 * In order to permit views to be nested within
875 * other views, we need to flush the content back out whenever
876 * we are beyond the first level of output buffering so that
877 * it can be seen and included properly by the first included
878 * template and any subsequent ones. Oy!
Barry Mienydd671972010-10-04 16:33:58 +0200879 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000880 if (ob_get_level() > $this->_ci_ob_level + 1)
881 {
882 ob_end_flush();
883 }
884 else
885 {
Greg Aker22f1a632010-11-10 15:34:35 -0600886 $_ci_CI->output->append_output(ob_get_contents());
Derek Allard2067d1a2008-11-13 22:59:24 +0000887 @ob_end_clean();
888 }
889 }
890
891 // --------------------------------------------------------------------
892
893 /**
894 * Load class
895 *
896 * This function loads the requested class.
897 *
Barry Mienydd671972010-10-04 16:33:58 +0200898 * @param string the item that is being loaded
Derek Allard2067d1a2008-11-13 22:59:24 +0000899 * @param mixed any additional parameters
900 * @param string an optional object name
Barry Mienydd671972010-10-04 16:33:58 +0200901 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000902 */
Greg Akerf5c84022011-04-19 17:13:03 -0500903 protected function _ci_load_class($class, $params = NULL, $object_name = NULL)
Barry Mienydd671972010-10-04 16:33:58 +0200904 {
905 // Get the class name, and while we're at it trim any slashes.
906 // The directory path can be included as part of the class name,
Derek Allard2067d1a2008-11-13 22:59:24 +0000907 // but we don't want a leading slash
Greg Aker3a746652011-04-19 10:59:47 -0500908 $class = str_replace('.php', '', trim($class, '/'));
Barry Mienydd671972010-10-04 16:33:58 +0200909
Derek Allard2067d1a2008-11-13 22:59:24 +0000910 // Was the path included with the class name?
911 // We look for a slash to determine this
912 $subdir = '';
Derek Jones32bf1862010-03-02 13:46:07 -0600913 if (($last_slash = strrpos($class, '/')) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000914 {
Derek Jones32bf1862010-03-02 13:46:07 -0600915 // Extract the path
Andrey Andreevd7297352012-01-07 22:53:14 +0200916 $subdir = substr($class, 0, ++$last_slash);
Barry Mienydd671972010-10-04 16:33:58 +0200917
Derek Jones32bf1862010-03-02 13:46:07 -0600918 // Get the filename from the path
Andrey Andreevd7297352012-01-07 22:53:14 +0200919 $class = substr($class, $last_slash);
dchill425628ba02012-08-08 12:05:45 -0400920
921 // Check for match and driver base class
dchill42aee92652012-08-26 21:45:35 -0400922 if (strtolower(trim($subdir, '/')) == strtolower($class) && ! class_exists('CI_Driver_Library'))
dchill425628ba02012-08-08 12:05:45 -0400923 {
924 // We aren't instantiating an object here, just making the base class available
925 require BASEPATH.'libraries/Driver.php';
926 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000927 }
928
929 // We'll test for both lowercase and capitalized versions of the file name
930 foreach (array(ucfirst($class), strtolower($class)) as $class)
931 {
Greg Aker3a746652011-04-19 10:59:47 -0500932 $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php';
Derek Allard2067d1a2008-11-13 22:59:24 +0000933
Barry Mienydd671972010-10-04 16:33:58 +0200934 // Is this a class extension request?
Derek Allard2067d1a2008-11-13 22:59:24 +0000935 if (file_exists($subclass))
936 {
Greg Aker3a746652011-04-19 10:59:47 -0500937 $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php';
Barry Mienydd671972010-10-04 16:33:58 +0200938
Derek Allard2067d1a2008-11-13 22:59:24 +0000939 if ( ! file_exists($baseclass))
940 {
Andrey Andreevd7297352012-01-07 22:53:14 +0200941 log_message('error', 'Unable to load the requested class: '.$class);
942 show_error('Unable to load the requested class: '.$class);
Derek Allard2067d1a2008-11-13 22:59:24 +0000943 }
944
Andrey Andreevd7297352012-01-07 22:53:14 +0200945 // Safety: Was the class already loaded by a previous call?
Derek Allard2067d1a2008-11-13 22:59:24 +0000946 if (in_array($subclass, $this->_ci_loaded_files))
947 {
948 // Before we deem this to be a duplicate request, let's see
Andrey Andreevd7297352012-01-07 22:53:14 +0200949 // if a custom object name is being supplied. If so, we'll
Derek Allard2067d1a2008-11-13 22:59:24 +0000950 // return a new instance of the object
951 if ( ! is_null($object_name))
952 {
953 $CI =& get_instance();
954 if ( ! isset($CI->$object_name))
955 {
Barry Mienydd671972010-10-04 16:33:58 +0200956 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000957 }
958 }
Barry Mienydd671972010-10-04 16:33:58 +0200959
Derek Allard2067d1a2008-11-13 22:59:24 +0000960 $is_duplicate = TRUE;
Andrey Andreevd7297352012-01-07 22:53:14 +0200961 log_message('debug', $class.' class already loaded. Second attempt ignored.');
Derek Allard2067d1a2008-11-13 22:59:24 +0000962 return;
963 }
Barry Mienydd671972010-10-04 16:33:58 +0200964
965 include_once($baseclass);
Derek Allard2067d1a2008-11-13 22:59:24 +0000966 include_once($subclass);
967 $this->_ci_loaded_files[] = $subclass;
Barry Mienydd671972010-10-04 16:33:58 +0200968
969 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000970 }
Barry Mienydd671972010-10-04 16:33:58 +0200971
Derek Allard2067d1a2008-11-13 22:59:24 +0000972 // Lets search for the requested library file and load it.
Derek Jones32bf1862010-03-02 13:46:07 -0600973 $is_duplicate = FALSE;
974 foreach ($this->_ci_library_paths as $path)
Derek Allard2067d1a2008-11-13 22:59:24 +0000975 {
Greg Aker3a746652011-04-19 10:59:47 -0500976 $filepath = $path.'libraries/'.$subdir.$class.'.php';
Derek Jones32bf1862010-03-02 13:46:07 -0600977
Andrey Andreevd7297352012-01-07 22:53:14 +0200978 // Does the file exist? No? Bummer...
Derek Allard2067d1a2008-11-13 22:59:24 +0000979 if ( ! file_exists($filepath))
980 {
981 continue;
982 }
Barry Mienydd671972010-10-04 16:33:58 +0200983
Andrey Andreevd7297352012-01-07 22:53:14 +0200984 // Safety: Was the class already loaded by a previous call?
Derek Allard2067d1a2008-11-13 22:59:24 +0000985 if (in_array($filepath, $this->_ci_loaded_files))
986 {
987 // Before we deem this to be a duplicate request, let's see
Andrey Andreevd7297352012-01-07 22:53:14 +0200988 // if a custom object name is being supplied. If so, we'll
Derek Allard2067d1a2008-11-13 22:59:24 +0000989 // return a new instance of the object
990 if ( ! is_null($object_name))
991 {
992 $CI =& get_instance();
993 if ( ! isset($CI->$object_name))
994 {
995 return $this->_ci_init_class($class, '', $params, $object_name);
996 }
997 }
Barry Mienydd671972010-10-04 16:33:58 +0200998
Derek Allard2067d1a2008-11-13 22:59:24 +0000999 $is_duplicate = TRUE;
Andrey Andreevd7297352012-01-07 22:53:14 +02001000 log_message('debug', $class.' class already loaded. Second attempt ignored.');
Derek Allard2067d1a2008-11-13 22:59:24 +00001001 return;
1002 }
Barry Mienydd671972010-10-04 16:33:58 +02001003
Derek Allard2067d1a2008-11-13 22:59:24 +00001004 include_once($filepath);
1005 $this->_ci_loaded_files[] = $filepath;
Barry Mienydd671972010-10-04 16:33:58 +02001006 return $this->_ci_init_class($class, '', $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +00001007 }
1008 } // END FOREACH
1009
Andrey Andreevd7297352012-01-07 22:53:14 +02001010 // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified?
Alex Bilbieed944a32012-06-02 11:07:47 +01001011 if ($subdir === '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001012 {
1013 $path = strtolower($class).'/'.$class;
dchill420fc3be52012-08-27 20:54:23 -04001014 return $this->_ci_load_class($path, $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +00001015 }
dchill42aee92652012-08-26 21:45:35 -04001016 else if (ucfirst($subdir) != $subdir)
1017 {
1018 // Lowercase subdir failed - retry capitalized
1019 $path = ucfirst($subdir).$class;
dchill420fc3be52012-08-27 20:54:23 -04001020 return $this->_ci_load_class($path, $params, $object_name);
dchill42aee92652012-08-26 21:45:35 -04001021 }
Barry Mienydd671972010-10-04 16:33:58 +02001022
Derek Allard2067d1a2008-11-13 22:59:24 +00001023 // If we got this far we were unable to find the requested class.
1024 // We do not issue errors if the load call failed due to a duplicate request
Alex Bilbieed944a32012-06-02 11:07:47 +01001025 if ($is_duplicate === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001026 {
Andrey Andreevd7297352012-01-07 22:53:14 +02001027 log_message('error', 'Unable to load the requested class: '.$class);
1028 show_error('Unable to load the requested class: '.$class);
Derek Allard2067d1a2008-11-13 22:59:24 +00001029 }
1030 }
Barry Mienydd671972010-10-04 16:33:58 +02001031
Derek Allard2067d1a2008-11-13 22:59:24 +00001032 // --------------------------------------------------------------------
1033
1034 /**
1035 * Instantiates a class
1036 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001037 * @param string
1038 * @param string
David Behlercda768a2011-08-14 23:52:48 +02001039 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +00001040 * @param string an optional object name
Andrey Andreev94af3552012-03-26 23:10:42 +03001041 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +00001042 */
Greg Aker0c9ee4a2011-04-20 09:40:17 -05001043 protected function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL)
Barry Mienydd671972010-10-04 16:33:58 +02001044 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001045 // Is there an associated config file for this class? Note: these should always be lowercase
Derek Allard2067d1a2008-11-13 22:59:24 +00001046 if ($config === NULL)
1047 {
Eric Barnes5e16ec62011-01-04 17:25:23 -05001048 // Fetch the config paths containing any package paths
1049 $config_component = $this->_ci_get_component('config');
1050
1051 if (is_array($config_component->_config_paths))
Derek Allard2067d1a2008-11-13 22:59:24 +00001052 {
Eric Barnes5e16ec62011-01-04 17:25:23 -05001053 // Break on the first found file, thus package files
1054 // are not overridden by default paths
1055 foreach ($config_component->_config_paths as $path)
1056 {
1057 // We test for both uppercase and lowercase, for servers that
joelcox1bfd9fa2011-01-16 18:49:39 +01001058 // are case-sensitive with regard to file names. Check for environment
1059 // first, global next
Andrey Andreev94af3552012-03-26 23:10:42 +03001060 if (defined('ENVIRONMENT') && file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'))
joelcox1bfd9fa2011-01-16 18:49:39 +01001061 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001062 include($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php');
joelcox1bfd9fa2011-01-16 18:49:39 +01001063 break;
1064 }
Andrey Andreev94af3552012-03-26 23:10:42 +03001065 elseif (defined('ENVIRONMENT') && file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'))
joelcox1bfd9fa2011-01-16 18:49:39 +01001066 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001067 include($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php');
joelcox1bfd9fa2011-01-16 18:49:39 +01001068 break;
1069 }
Andrey Andreev94af3552012-03-26 23:10:42 +03001070 elseif (file_exists($path.'config/'.strtolower($class).'.php'))
Eric Barnes5e16ec62011-01-04 17:25:23 -05001071 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001072 include($path.'config/'.strtolower($class).'.php');
Eric Barnes5e16ec62011-01-04 17:25:23 -05001073 break;
1074 }
Andrey Andreev94af3552012-03-26 23:10:42 +03001075 elseif (file_exists($path.'config/'.ucfirst(strtolower($class)).'.php'))
Eric Barnes5e16ec62011-01-04 17:25:23 -05001076 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001077 include($path.'config/'.ucfirst(strtolower($class)).'.php');
Eric Barnes5e16ec62011-01-04 17:25:23 -05001078 break;
1079 }
1080 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001081 }
1082 }
Barry Mienydd671972010-10-04 16:33:58 +02001083
Alex Bilbieed944a32012-06-02 11:07:47 +01001084 if ($prefix === '')
Barry Mienydd671972010-10-04 16:33:58 +02001085 {
1086 if (class_exists('CI_'.$class))
Derek Allard2067d1a2008-11-13 22:59:24 +00001087 {
1088 $name = 'CI_'.$class;
1089 }
Barry Mienydd671972010-10-04 16:33:58 +02001090 elseif (class_exists(config_item('subclass_prefix').$class))
Derek Allard2067d1a2008-11-13 22:59:24 +00001091 {
1092 $name = config_item('subclass_prefix').$class;
1093 }
1094 else
1095 {
1096 $name = $class;
1097 }
1098 }
1099 else
1100 {
1101 $name = $prefix.$class;
1102 }
Barry Mienydd671972010-10-04 16:33:58 +02001103
Derek Allard2067d1a2008-11-13 22:59:24 +00001104 // Is the class name valid?
1105 if ( ! class_exists($name))
1106 {
Andrey Andreevd7297352012-01-07 22:53:14 +02001107 log_message('error', 'Non-existent class: '.$name);
jonnueee2df62012-07-16 13:06:16 +01001108 show_error('Non-existent class: '.$name);
Derek Allard2067d1a2008-11-13 22:59:24 +00001109 }
Barry Mienydd671972010-10-04 16:33:58 +02001110
Derek Allard2067d1a2008-11-13 22:59:24 +00001111 // Set the variable name we will assign the class to
Andrey Andreevd7297352012-01-07 22:53:14 +02001112 // Was a custom class name supplied? If so we'll use it
Derek Allard2067d1a2008-11-13 22:59:24 +00001113 $class = strtolower($class);
Barry Mienydd671972010-10-04 16:33:58 +02001114
Derek Allard2067d1a2008-11-13 22:59:24 +00001115 if (is_null($object_name))
1116 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001117 $classvar = isset($this->_ci_varmap[$class]) ? $this->_ci_varmap[$class] : $class;
Derek Allard2067d1a2008-11-13 22:59:24 +00001118 }
1119 else
1120 {
1121 $classvar = $object_name;
1122 }
1123
Barry Mienydd671972010-10-04 16:33:58 +02001124 // Save the class name and object name
Derek Allard2067d1a2008-11-13 22:59:24 +00001125 $this->_ci_classes[$class] = $classvar;
1126
Barry Mienydd671972010-10-04 16:33:58 +02001127 // Instantiate the class
Derek Allard2067d1a2008-11-13 22:59:24 +00001128 $CI =& get_instance();
1129 if ($config !== NULL)
1130 {
1131 $CI->$classvar = new $name($config);
1132 }
1133 else
Barry Mienydd671972010-10-04 16:33:58 +02001134 {
Andrey Andreeva11b16b2012-03-28 12:22:04 +03001135 $CI->$classvar = new $name();
Barry Mienydd671972010-10-04 16:33:58 +02001136 }
1137 }
1138
Derek Allard2067d1a2008-11-13 22:59:24 +00001139 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001140
Derek Allard2067d1a2008-11-13 22:59:24 +00001141 /**
1142 * Autoloader
1143 *
1144 * The config/autoload.php file contains an array that permits sub-systems,
Derek Jonesc6da5032010-03-09 20:44:27 -06001145 * libraries, and helpers to be loaded automatically.
Derek Allard2067d1a2008-11-13 22:59:24 +00001146 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001147 * @return void
1148 */
Shane Pearson665baec2011-08-22 18:52:19 -05001149 protected function _ci_autoloader()
Barry Mienydd671972010-10-04 16:33:58 +02001150 {
dchill4260d100f2012-08-29 12:58:26 -04001151 if (defined('ENVIRONMENT') && file_exists($this->_ci_autoloader_path.'config/'.ENVIRONMENT.'/autoload.php'))
bubbafoley0ea04142011-03-17 14:55:41 -05001152 {
dchill4260d100f2012-08-29 12:58:26 -04001153 include($this->_ci_autoloader_path.'config/'.ENVIRONMENT.'/autoload.php');
bubbafoley0ea04142011-03-17 14:55:41 -05001154 }
1155 else
1156 {
dchill4260d100f2012-08-29 12:58:26 -04001157 include($this->_ci_autoloader_path.'config/autoload.php');
bubbafoley0ea04142011-03-17 14:55:41 -05001158 }
Barry Mienydd671972010-10-04 16:33:58 +02001159
Derek Allard2067d1a2008-11-13 22:59:24 +00001160 if ( ! isset($autoload))
1161 {
1162 return FALSE;
1163 }
Barry Mienydd671972010-10-04 16:33:58 +02001164
Phil Sturgeon9730c752010-12-15 10:50:15 +00001165 // Autoload packages
1166 if (isset($autoload['packages']))
1167 {
1168 foreach ($autoload['packages'] as $package_path)
1169 {
1170 $this->add_package_path($package_path);
1171 }
1172 }
1173
Derek Allard2067d1a2008-11-13 22:59:24 +00001174 // Load any custom config file
1175 if (count($autoload['config']) > 0)
Barry Mienydd671972010-10-04 16:33:58 +02001176 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001177 $CI =& get_instance();
1178 foreach ($autoload['config'] as $key => $val)
1179 {
1180 $CI->config->load($val);
1181 }
Barry Mienydd671972010-10-04 16:33:58 +02001182 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001183
Derek Jonesc6da5032010-03-09 20:44:27 -06001184 // Autoload helpers and languages
1185 foreach (array('helper', 'language') as $type)
Barry Mienydd671972010-10-04 16:33:58 +02001186 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001187 if (isset($autoload[$type]) && count($autoload[$type]) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001188 {
1189 $this->$type($autoload[$type]);
Barry Mienydd671972010-10-04 16:33:58 +02001190 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001191 }
1192
Derek Allard2067d1a2008-11-13 22:59:24 +00001193 // Load libraries
Andrey Andreev94af3552012-03-26 23:10:42 +03001194 if (isset($autoload['libraries']) && count($autoload['libraries']) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001195 {
1196 // Load the database driver.
1197 if (in_array('database', $autoload['libraries']))
1198 {
1199 $this->database();
1200 $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
1201 }
Barry Mienydd671972010-10-04 16:33:58 +02001202
Derek Allard2067d1a2008-11-13 22:59:24 +00001203 // Load all other libraries
1204 foreach ($autoload['libraries'] as $item)
1205 {
1206 $this->library($item);
1207 }
Barry Mienydd671972010-10-04 16:33:58 +02001208 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001209
Darren Hillc4e266b2011-08-30 15:40:27 -04001210 // Autoload drivers
1211 if (isset($autoload['drivers']))
1212 {
Darren Hillca3be1d2011-08-31 08:31:18 -04001213 foreach ($autoload['drivers'] as $item)
1214 {
1215 $this->driver($item);
1216 }
Darren Hillc4e266b2011-08-30 15:40:27 -04001217 }
1218
Derek Allard2067d1a2008-11-13 22:59:24 +00001219 // Autoload models
1220 if (isset($autoload['model']))
1221 {
1222 $this->model($autoload['model']);
1223 }
Barry Mienydd671972010-10-04 16:33:58 +02001224 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001225
1226 // --------------------------------------------------------------------
1227
1228 /**
1229 * Object to Array
1230 *
1231 * Takes an object as input and converts the class variables to array key/vals
1232 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001233 * @param object
1234 * @return array
1235 */
Greg Akerf5c84022011-04-19 17:13:03 -05001236 protected function _ci_object_to_array($object)
Derek Allard2067d1a2008-11-13 22:59:24 +00001237 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001238 return is_object($object) ? get_object_vars($object) : $object;
Derek Allard2067d1a2008-11-13 22:59:24 +00001239 }
1240
1241 // --------------------------------------------------------------------
1242
1243 /**
Derek Jones32bf1862010-03-02 13:46:07 -06001244 * Get a reference to a specific library or model
1245 *
David Behlercda768a2011-08-14 23:52:48 +02001246 * @param string
Derek Jones32bf1862010-03-02 13:46:07 -06001247 * @return bool
1248 */
Greg Akerf5c84022011-04-19 17:13:03 -05001249 protected function &_ci_get_component($component)
Derek Jones32bf1862010-03-02 13:46:07 -06001250 {
Pascal Kriete89ace432010-11-10 15:49:10 -05001251 $CI =& get_instance();
1252 return $CI->$component;
Derek Jones32bf1862010-03-02 13:46:07 -06001253 }
1254
1255 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001256
Derek Jones32bf1862010-03-02 13:46:07 -06001257 /**
1258 * Prep filename
1259 *
1260 * This function preps the name of various items to make loading them more reliable.
1261 *
Derek Jones32bf1862010-03-02 13:46:07 -06001262 * @param mixed
David Behlercda768a2011-08-14 23:52:48 +02001263 * @param string
Derek Jones32bf1862010-03-02 13:46:07 -06001264 * @return array
1265 */
Greg Akerf5c84022011-04-19 17:13:03 -05001266 protected function _ci_prep_filename($filename, $extension)
Derek Jones32bf1862010-03-02 13:46:07 -06001267 {
1268 if ( ! is_array($filename))
Barry Mienydd671972010-10-04 16:33:58 +02001269 {
Andrey Andreevd47baab2012-01-09 16:56:46 +02001270 return array(strtolower(str_replace(array($extension, '.php'), '', $filename).$extension));
Derek Jones32bf1862010-03-02 13:46:07 -06001271 }
1272 else
1273 {
1274 foreach ($filename as $key => $val)
1275 {
Andrey Andreevd47baab2012-01-09 16:56:46 +02001276 $filename[$key] = strtolower(str_replace(array($extension, '.php'), '', $val).$extension);
Derek Jones32bf1862010-03-02 13:46:07 -06001277 }
Barry Mienydd671972010-10-04 16:33:58 +02001278
Derek Jones32bf1862010-03-02 13:46:07 -06001279 return $filename;
1280 }
1281 }
Andrey Andreev94af3552012-03-26 23:10:42 +03001282
Derek Allard2067d1a2008-11-13 22:59:24 +00001283}
1284
1285/* End of file Loader.php */
Darren Hillc4e266b2011-08-30 15:40:27 -04001286/* Location: ./system/core/Loader.php */