blob: b316c8e1bfc6ec84aa32d6e73d6e7fe6f0e49cc2 [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 /**
78 * List of loaded base classes
David Behlercda768a2011-08-14 23:52:48 +020079 *
80 * @var array
David Behlercda768a2011-08-14 23:52:48 +020081 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040082 protected $_base_classes = array(); // Set by the controller class
Andrey Andreev92ebfb62012-05-17 12:49:24 +030083
David Behlercda768a2011-08-14 23:52:48 +020084 /**
85 * List of cached variables
86 *
87 * @var array
David Behlercda768a2011-08-14 23:52:48 +020088 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040089 protected $_ci_cached_vars = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030090
David Behlercda768a2011-08-14 23:52:48 +020091 /**
92 * List of loaded classes
93 *
94 * @var array
David Behlercda768a2011-08-14 23:52:48 +020095 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040096 protected $_ci_classes = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030097
David Behlercda768a2011-08-14 23:52:48 +020098 /**
99 * List of loaded files
100 *
101 * @var array
David Behlercda768a2011-08-14 23:52:48 +0200102 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -0400103 protected $_ci_loaded_files = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300104
David Behlercda768a2011-08-14 23:52:48 +0200105 /**
106 * List of loaded models
107 *
108 * @var array
David Behlercda768a2011-08-14 23:52:48 +0200109 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -0400110 protected $_ci_models = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300111
David Behlercda768a2011-08-14 23:52:48 +0200112 /**
113 * List of loaded helpers
114 *
115 * @var array
David Behlercda768a2011-08-14 23:52:48 +0200116 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -0400117 protected $_ci_helpers = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300118
David Behlercda768a2011-08-14 23:52:48 +0200119 /**
120 * List of class name mappings
121 *
122 * @var array
David Behlercda768a2011-08-14 23:52:48 +0200123 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -0400124 protected $_ci_varmap = array(
Timothy Warren40403d22012-04-19 16:38:50 -0400125 'unit_test' => 'unit',
126 'user_agent' => 'agent'
127 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000128
129 /**
130 * Constructor
131 *
132 * Sets the path to the view files and gets the initial output buffering level
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300133 *
134 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 */
Greg Akerf5c84022011-04-19 17:13:03 -0500136 public function __construct()
Barry Mienydd671972010-10-04 16:33:58 +0200137 {
Derek Jones37f4b9c2011-07-01 17:56:50 -0500138 $this->_ci_ob_level = ob_get_level();
Derek Jones32bf1862010-03-02 13:46:07 -0600139 $this->_ci_library_paths = array(APPPATH, BASEPATH);
140 $this->_ci_helper_paths = array(APPPATH, BASEPATH);
141 $this->_ci_model_paths = array(APPPATH);
Joe Cianflone8eef9c72011-08-21 10:39:06 -0400142 $this->_ci_view_paths = array(VIEWPATH => TRUE);
David Behlercda768a2011-08-14 23:52:48 +0200143
Andrey Andreevd7297352012-01-07 22:53:14 +0200144 log_message('debug', 'Loader Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 }
Barry Mienydd671972010-10-04 16:33:58 +0200146
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 // --------------------------------------------------------------------
David Behlercda768a2011-08-14 23:52:48 +0200148
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500149 /**
Shane Pearson6adfe632011-08-10 16:42:53 -0500150 * Initialize the Loader
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500151 *
152 * This method is called once in CI_Controller.
153 *
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500154 * @return object
155 */
Shane Pearson6adfe632011-08-10 16:42:53 -0500156 public function initialize()
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500157 {
Shane Pearson6adfe632011-08-10 16:42:53 -0500158 $this->_ci_classes = array();
159 $this->_ci_loaded_files = array();
160 $this->_ci_models = array();
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500161 $this->_base_classes =& is_loaded();
Shane Pearson6adfe632011-08-10 16:42:53 -0500162
163 $this->_ci_autoloader();
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500164 return $this;
165 }
166
167 // --------------------------------------------------------------------
168
169 /**
170 * Is Loaded
171 *
172 * A utility function to test if a class is in the self::$_ci_classes array.
173 * This function returns the object name if the class tested for is loaded,
174 * and returns FALSE if it isn't.
175 *
176 * It is mainly used in the form_helper -> _get_validation_object()
177 *
178 * @param string class being checked for
179 * @return mixed class object name on the CI SuperObject or FALSE
180 */
181 public function is_loaded($class)
182 {
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300183 return isset($this->_ci_classes[$class]) ? $this->_ci_classes[$class] : FALSE;
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500184 }
185
186 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200187
Derek Allard2067d1a2008-11-13 22:59:24 +0000188 /**
189 * Class Loader
190 *
191 * This function lets users load and instantiate classes.
192 * It is designed to be called from a user's app controllers.
193 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000194 * @param string the name of the class
195 * @param mixed the optional parameters
196 * @param string an optional object name
197 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200198 */
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500199 public function library($library = '', $params = NULL, $object_name = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000200 {
Greg Akerce433962010-10-12 09:29:35 -0500201 if (is_array($library))
202 {
Phil Sturgeon08b51692011-04-03 18:05:42 +0100203 foreach ($library as $class)
Greg Akerce433962010-10-12 09:29:35 -0500204 {
Kellas Reeves3c6e4852011-02-09 11:57:56 -0600205 $this->library($class, $params);
Greg Akerce433962010-10-12 09:29:35 -0500206 }
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000207
Greg Akerce433962010-10-12 09:29:35 -0500208 return;
209 }
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000210
Alex Bilbieed944a32012-06-02 11:07:47 +0100211 if ($library === '' OR isset($this->_base_classes[$library]))
Derek Allard2067d1a2008-11-13 22:59:24 +0000212 {
213 return FALSE;
214 }
215
Derek Jones32bf1862010-03-02 13:46:07 -0600216 if ( ! is_null($params) && ! is_array($params))
Derek Allard2067d1a2008-11-13 22:59:24 +0000217 {
218 $params = NULL;
219 }
220
Kellas Reeves3c6e4852011-02-09 11:57:56 -0600221 $this->_ci_load_class($library, $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000222 }
223
224 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200225
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 /**
227 * Model Loader
228 *
229 * This function lets users load and instantiate models.
230 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000231 * @param string the name of the class
232 * @param string name for the model
233 * @param bool database connection
234 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200235 */
Greg Akerf5c84022011-04-19 17:13:03 -0500236 public function model($model, $name = '', $db_conn = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200237 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000238 if (is_array($model))
239 {
Joel Limberg3cf174b2012-07-13 20:49:57 +0300240 foreach ($model as $class)
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 {
Joel Limberg3cf174b2012-07-13 20:49:57 +0300242 $this->model($class);
Derek Allard2067d1a2008-11-13 22:59:24 +0000243 }
244 return;
245 }
246
Alex Bilbieed944a32012-06-02 11:07:47 +0100247 if ($model === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000248 {
249 return;
250 }
Barry Mienydd671972010-10-04 16:33:58 +0200251
Derek Jones32bf1862010-03-02 13:46:07 -0600252 $path = '';
Barry Mienydd671972010-10-04 16:33:58 +0200253
Derek Allard2067d1a2008-11-13 22:59:24 +0000254 // Is the model in a sub-folder? If so, parse out the filename and path.
Derek Jones32bf1862010-03-02 13:46:07 -0600255 if (($last_slash = strrpos($model, '/')) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000256 {
Derek Jones32bf1862010-03-02 13:46:07 -0600257 // The path is in front of the last slash
Andrey Andreevd47baab2012-01-09 16:56:46 +0200258 $path = substr($model, 0, ++$last_slash);
Derek Jones32bf1862010-03-02 13:46:07 -0600259
260 // And the model name behind it
Andrey Andreevd47baab2012-01-09 16:56:46 +0200261 $model = substr($model, $last_slash);
Derek Allard2067d1a2008-11-13 22:59:24 +0000262 }
Barry Mienydd671972010-10-04 16:33:58 +0200263
Phil Sturgeon10d78f62012-06-04 14:41:53 -0500264 if (empty($name))
Derek Allard2067d1a2008-11-13 22:59:24 +0000265 {
266 $name = $model;
267 }
Barry Mienydd671972010-10-04 16:33:58 +0200268
Derek Allard2067d1a2008-11-13 22:59:24 +0000269 if (in_array($name, $this->_ci_models, TRUE))
270 {
271 return;
272 }
Barry Mienydd671972010-10-04 16:33:58 +0200273
Derek Allard2067d1a2008-11-13 22:59:24 +0000274 $CI =& get_instance();
275 if (isset($CI->$name))
276 {
277 show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
278 }
Barry Mienydd671972010-10-04 16:33:58 +0200279
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 $model = strtolower($model);
Derek Allard2067d1a2008-11-13 22:59:24 +0000281
Derek Jones32bf1862010-03-02 13:46:07 -0600282 foreach ($this->_ci_model_paths as $mod_path)
283 {
Greg Aker3a746652011-04-19 10:59:47 -0500284 if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
Derek Jones32bf1862010-03-02 13:46:07 -0600285 {
286 continue;
287 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000288
Andrey Andreev94af3552012-03-26 23:10:42 +0300289 if ($db_conn !== FALSE && ! class_exists('CI_DB'))
Derek Jones32bf1862010-03-02 13:46:07 -0600290 {
291 if ($db_conn === TRUE)
Pascal Kriete287781e2010-11-10 15:43:49 -0500292 {
Derek Jones32bf1862010-03-02 13:46:07 -0600293 $db_conn = '';
Pascal Kriete287781e2010-11-10 15:43:49 -0500294 }
Derek Jones32bf1862010-03-02 13:46:07 -0600295
296 $CI->load->database($db_conn, FALSE, TRUE);
297 }
298
Greg Akerbce13482010-10-11 15:37:16 -0500299 if ( ! class_exists('CI_Model'))
Derek Jones32bf1862010-03-02 13:46:07 -0600300 {
301 load_class('Model', 'core');
302 }
303
Greg Aker3a746652011-04-19 10:59:47 -0500304 require_once($mod_path.'models/'.$path.$model.'.php');
Derek Jones32bf1862010-03-02 13:46:07 -0600305
306 $model = ucfirst($model);
Derek Jones32bf1862010-03-02 13:46:07 -0600307 $CI->$name = new $model();
Derek Jones32bf1862010-03-02 13:46:07 -0600308 $this->_ci_models[] = $name;
309 return;
310 }
Barry Mienydd671972010-10-04 16:33:58 +0200311
Derek Jones32bf1862010-03-02 13:46:07 -0600312 // couldn't find the model
313 show_error('Unable to locate the model you have specified: '.$model);
Derek Allard2067d1a2008-11-13 22:59:24 +0000314 }
Barry Mienydd671972010-10-04 16:33:58 +0200315
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200317
Derek Allard2067d1a2008-11-13 22:59:24 +0000318 /**
319 * Database Loader
320 *
Andrey Andreev9d0ab042012-10-24 21:47:39 +0300321 * @param mixed $params = '' the DB settings
322 * @param bool $return = FALSE whether to return the DB object
323 * @param bool $query_builder = NULL whether to enable query builder (overrides the config setting)
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 * @return object
Barry Mienydd671972010-10-04 16:33:58 +0200325 */
Jamie Rumbelow7efad202012-02-19 12:37:00 +0000326 public function database($params = '', $return = FALSE, $query_builder = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000327 {
328 // Grab the super object
329 $CI =& get_instance();
Barry Mienydd671972010-10-04 16:33:58 +0200330
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 // Do we even need to load the database class?
Andrey Andreev9d0ab042012-10-24 21:47:39 +0300332 if ($return === FALSE && $query_builder === NULL && isset($CI->db) && is_object($CI->db) && ! empty($CI->db->conn_id))
Derek Allard2067d1a2008-11-13 22:59:24 +0000333 {
334 return FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200335 }
336
Greg Aker3a746652011-04-19 10:59:47 -0500337 require_once(BASEPATH.'database/DB.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000338
339 if ($return === TRUE)
340 {
Jamie Rumbelow7efad202012-02-19 12:37:00 +0000341 return DB($params, $query_builder);
Derek Allard2067d1a2008-11-13 22:59:24 +0000342 }
Barry Mienydd671972010-10-04 16:33:58 +0200343
Andrey Andreevd7297352012-01-07 22:53:14 +0200344 // Initialize the db variable. Needed to prevent
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 // reference errors with some configurations
346 $CI->db = '';
Barry Mienydd671972010-10-04 16:33:58 +0200347
Derek Allard2067d1a2008-11-13 22:59:24 +0000348 // Load the DB class
Jamie Rumbelow7efad202012-02-19 12:37:00 +0000349 $CI->db =& DB($params, $query_builder);
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 }
Barry Mienydd671972010-10-04 16:33:58 +0200351
Derek Allard2067d1a2008-11-13 22:59:24 +0000352 // --------------------------------------------------------------------
353
354 /**
355 * Load the Utilities Class
356 *
Barry Mienydd671972010-10-04 16:33:58 +0200357 * @return string
358 */
Greg Akerf5c84022011-04-19 17:13:03 -0500359 public function dbutil()
Derek Allard2067d1a2008-11-13 22:59:24 +0000360 {
361 if ( ! class_exists('CI_DB'))
362 {
363 $this->database();
364 }
Barry Mienydd671972010-10-04 16:33:58 +0200365
Derek Allard2067d1a2008-11-13 22:59:24 +0000366 $CI =& get_instance();
367
368 // for backwards compatibility, load dbforge so we can extend dbutils off it
369 // this use is deprecated and strongly discouraged
370 $CI->load->dbforge();
Barry Mienydd671972010-10-04 16:33:58 +0200371
Greg Aker3a746652011-04-19 10:59:47 -0500372 require_once(BASEPATH.'database/DB_utility.php');
373 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
375
Pascal Kriete58560022010-11-10 16:01:20 -0500376 $CI->dbutil = new $class();
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 }
Barry Mienydd671972010-10-04 16:33:58 +0200378
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 // --------------------------------------------------------------------
380
381 /**
382 * Load the Database Forge Class
383 *
Barry Mienydd671972010-10-04 16:33:58 +0200384 * @return string
385 */
Greg Akerf5c84022011-04-19 17:13:03 -0500386 public function dbforge()
Derek Allard2067d1a2008-11-13 22:59:24 +0000387 {
388 if ( ! class_exists('CI_DB'))
389 {
390 $this->database();
391 }
Barry Mienydd671972010-10-04 16:33:58 +0200392
Derek Allard2067d1a2008-11-13 22:59:24 +0000393 $CI =& get_instance();
Barry Mienydd671972010-10-04 16:33:58 +0200394
Greg Aker3a746652011-04-19 10:59:47 -0500395 require_once(BASEPATH.'database/DB_forge.php');
396 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000397 $class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
398
399 $CI->dbforge = new $class();
Derek Allard2067d1a2008-11-13 22:59:24 +0000400 }
Barry Mienydd671972010-10-04 16:33:58 +0200401
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200403
Derek Allard2067d1a2008-11-13 22:59:24 +0000404 /**
405 * Load View
406 *
Andrey Andreev94af3552012-03-26 23:10:42 +0300407 * This function is used to load a "view" file. It has three parameters:
Derek Allard2067d1a2008-11-13 22:59:24 +0000408 *
409 * 1. The name of the "view" file to be included.
410 * 2. An associative array of data to be extracted for use in the view.
Andrey Andreev94af3552012-03-26 23:10:42 +0300411 * 3. TRUE/FALSE - whether to return the data or load it. In
dchill425628ba02012-08-08 12:05:45 -0400412 * some cases it's advantageous to be able to return data so that
413 * a developer can process it in some way.
Derek Allard2067d1a2008-11-13 22:59:24 +0000414 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 * @param string
416 * @param array
417 * @param bool
418 * @return void
419 */
Greg Akerf5c84022011-04-19 17:13:03 -0500420 public function view($view, $vars = array(), $return = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000421 {
422 return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
423 }
Barry Mienydd671972010-10-04 16:33:58 +0200424
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200426
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 /**
428 * Load File
429 *
430 * This is a generic file loader
431 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000432 * @param string
433 * @param bool
434 * @return string
435 */
Greg Akerf5c84022011-04-19 17:13:03 -0500436 public function file($path, $return = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000437 {
438 return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return));
439 }
Barry Mienydd671972010-10-04 16:33:58 +0200440
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200442
Derek Allard2067d1a2008-11-13 22:59:24 +0000443 /**
444 * Set Variables
445 *
446 * Once variables are set they become available within
447 * the controller class and its "view" files.
448 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000449 * @param array
David Behlercda768a2011-08-14 23:52:48 +0200450 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 * @return void
452 */
Greg Akerf5c84022011-04-19 17:13:03 -0500453 public function vars($vars = array(), $val = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000454 {
Alex Bilbieed944a32012-06-02 11:07:47 +0100455 if ($val !== '' && is_string($vars))
Derek Allard2067d1a2008-11-13 22:59:24 +0000456 {
457 $vars = array($vars => $val);
458 }
Barry Mienydd671972010-10-04 16:33:58 +0200459
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 $vars = $this->_ci_object_to_array($vars);
Barry Mienydd671972010-10-04 16:33:58 +0200461
Andrey Andreev94af3552012-03-26 23:10:42 +0300462 if (is_array($vars) && count($vars) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000463 {
464 foreach ($vars as $key => $val)
465 {
466 $this->_ci_cached_vars[$key] = $val;
467 }
468 }
469 }
Barry Mienydd671972010-10-04 16:33:58 +0200470
Derek Allard2067d1a2008-11-13 22:59:24 +0000471 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200472
Derek Allard2067d1a2008-11-13 22:59:24 +0000473 /**
Phil Sturgeon8731f642011-07-22 16:11:34 -0600474 * Get Variable
475 *
476 * Check if a variable is set and retrieve it.
477 *
478 * @param array
479 * @return void
480 */
481 public function get_var($key)
482 {
483 return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL;
484 }
485
486 // --------------------------------------------------------------------
487
488 /**
Shane Pearson81dd2232011-11-18 20:49:35 -0600489 * Get Variables
490 *
491 * Retrieve all loaded variables
492 *
493 * @return array
494 */
495 public function get_vars()
496 {
497 return $this->_ci_cached_vars;
498 }
499
500 // --------------------------------------------------------------------
501
502 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000503 * Load Helper
504 *
505 * This function loads the specified helper file.
506 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000507 * @param mixed
508 * @return void
509 */
Greg Akerf5c84022011-04-19 17:13:03 -0500510 public function helper($helpers = array())
Barry Mienydd671972010-10-04 16:33:58 +0200511 {
Derek Jones32bf1862010-03-02 13:46:07 -0600512 foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
Barry Mienydd671972010-10-04 16:33:58 +0200513 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000514 if (isset($this->_ci_helpers[$helper]))
515 {
516 continue;
517 }
Derek Jones32bf1862010-03-02 13:46:07 -0600518
Greg Aker3a746652011-04-19 10:59:47 -0500519 $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.'.php';
Derek Allard2067d1a2008-11-13 22:59:24 +0000520
Barry Mienydd671972010-10-04 16:33:58 +0200521 // Is this a helper extension request?
Derek Allard2067d1a2008-11-13 22:59:24 +0000522 if (file_exists($ext_helper))
523 {
Greg Aker3a746652011-04-19 10:59:47 -0500524 $base_helper = BASEPATH.'helpers/'.$helper.'.php';
Barry Mienydd671972010-10-04 16:33:58 +0200525
Derek Allard2067d1a2008-11-13 22:59:24 +0000526 if ( ! file_exists($base_helper))
527 {
Greg Aker3a746652011-04-19 10:59:47 -0500528 show_error('Unable to load the requested file: helpers/'.$helper.'.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000529 }
Barry Mienydd671972010-10-04 16:33:58 +0200530
Derek Allard2067d1a2008-11-13 22:59:24 +0000531 include_once($ext_helper);
532 include_once($base_helper);
Barry Mienydd671972010-10-04 16:33:58 +0200533
Derek Jones32bf1862010-03-02 13:46:07 -0600534 $this->_ci_helpers[$helper] = TRUE;
535 log_message('debug', 'Helper loaded: '.$helper);
536 continue;
Derek Allard2067d1a2008-11-13 22:59:24 +0000537 }
Barry Mienydd671972010-10-04 16:33:58 +0200538
Derek Jones32bf1862010-03-02 13:46:07 -0600539 // Try to load the helper
540 foreach ($this->_ci_helper_paths as $path)
541 {
Greg Aker3a746652011-04-19 10:59:47 -0500542 if (file_exists($path.'helpers/'.$helper.'.php'))
Barry Mienydd671972010-10-04 16:33:58 +0200543 {
Greg Aker3a746652011-04-19 10:59:47 -0500544 include_once($path.'helpers/'.$helper.'.php');
Derek Jones32bf1862010-03-02 13:46:07 -0600545
546 $this->_ci_helpers[$helper] = TRUE;
Barry Mienydd671972010-10-04 16:33:58 +0200547 log_message('debug', 'Helper loaded: '.$helper);
Derek Jones32bf1862010-03-02 13:46:07 -0600548 break;
Derek Allard2067d1a2008-11-13 22:59:24 +0000549 }
550 }
551
Derek Jones32bf1862010-03-02 13:46:07 -0600552 // unable to load the helper
553 if ( ! isset($this->_ci_helpers[$helper]))
554 {
Greg Aker3a746652011-04-19 10:59:47 -0500555 show_error('Unable to load the requested file: helpers/'.$helper.'.php');
Derek Jones32bf1862010-03-02 13:46:07 -0600556 }
Barry Mienydd671972010-10-04 16:33:58 +0200557 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000558 }
Barry Mienydd671972010-10-04 16:33:58 +0200559
Derek Allard2067d1a2008-11-13 22:59:24 +0000560 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200561
Derek Allard2067d1a2008-11-13 22:59:24 +0000562 /**
563 * Load Helpers
564 *
565 * This is simply an alias to the above function in case the
566 * user has written the plural form of this function.
567 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000568 * @param array
569 * @return void
570 */
Greg Akerf5c84022011-04-19 17:13:03 -0500571 public function helpers($helpers = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000572 {
573 $this->helper($helpers);
574 }
Barry Mienydd671972010-10-04 16:33:58 +0200575
Derek Allard2067d1a2008-11-13 22:59:24 +0000576 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200577
Derek Allard2067d1a2008-11-13 22:59:24 +0000578 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000579 * Loads a language file
580 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000581 * @param array
582 * @param string
583 * @return void
584 */
Greg Akerf5c84022011-04-19 17:13:03 -0500585 public function language($file = array(), $lang = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000586 {
587 $CI =& get_instance();
588
589 if ( ! is_array($file))
590 {
591 $file = array($file);
592 }
593
594 foreach ($file as $langfile)
Barry Mienydd671972010-10-04 16:33:58 +0200595 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000596 $CI->lang->load($langfile, $lang);
597 }
598 }
Barry Mienydd671972010-10-04 16:33:58 +0200599
Derek Allard2067d1a2008-11-13 22:59:24 +0000600 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200601
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 /**
603 * Loads a config file
604 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000605 * @param string
David Behlercda768a2011-08-14 23:52:48 +0200606 * @param bool
607 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000608 * @return void
609 */
Greg Akerf5c84022011-04-19 17:13:03 -0500610 public function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200611 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000612 $CI =& get_instance();
613 $CI->config->load($file, $use_sections, $fail_gracefully);
614 }
615
616 // --------------------------------------------------------------------
Derek Jones32bf1862010-03-02 13:46:07 -0600617
Derek Allard2067d1a2008-11-13 22:59:24 +0000618 /**
Derek Jones8dca0412010-03-05 13:01:44 -0600619 * Driver
620 *
621 * Loads a driver library
622 *
Christopher Guiney9929d6f2012-03-09 19:53:24 -0800623 * @param mixed the name of the class or array of classes
Derek Jones8dca0412010-03-05 13:01:44 -0600624 * @param mixed the optional parameters
625 * @param string an optional object name
626 * @return void
627 */
Greg Akerf5c84022011-04-19 17:13:03 -0500628 public function driver($library = '', $params = NULL, $object_name = NULL)
Derek Jones8dca0412010-03-05 13:01:44 -0600629 {
Christopher Guineyb54d3552012-03-10 08:38:10 -0800630 if (is_array($library))
Christopher Guiney9929d6f2012-03-09 19:53:24 -0800631 {
Christopher Guineyb54d3552012-03-10 08:38:10 -0800632 foreach ($library as $driver)
Christopher Guiney9929d6f2012-03-09 19:53:24 -0800633 {
634 $this->driver($driver);
635 }
dchill420fc3be52012-08-27 20:54:23 -0400636 return;
Christopher Guiney9929d6f2012-03-09 19:53:24 -0800637 }
638
Alex Bilbieed944a32012-06-02 11:07:47 +0100639 if ($library === '')
Tom Klingenberg6a15b2d2011-10-07 20:03:30 +0200640 {
641 return FALSE;
642 }
643
Derek Jonesd5e0cb52010-03-09 20:20:46 -0600644 // We can save the loader some time since Drivers will *always* be in a subfolder,
645 // and typically identically named to the library
646 if ( ! strpos($library, '/'))
647 {
Greg Akerd25e66a2010-03-28 01:07:09 -0500648 $library = ucfirst($library).'/'.$library;
Derek Jones8dca0412010-03-05 13:01:44 -0600649 }
Barry Mienydd671972010-10-04 16:33:58 +0200650
Derek Jones8dca0412010-03-05 13:01:44 -0600651 return $this->library($library, $params, $object_name);
652 }
653
654 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200655
Derek Jones8dca0412010-03-05 13:01:44 -0600656 /**
Derek Jones32bf1862010-03-02 13:46:07 -0600657 * Add Package Path
Derek Allard2067d1a2008-11-13 22:59:24 +0000658 *
Derek Jones32bf1862010-03-02 13:46:07 -0600659 * Prepends a parent path to the library, model, helper, and config path arrays
Derek Allard2067d1a2008-11-13 22:59:24 +0000660 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000661 * @param string
Andrey Andreev94af3552012-03-26 23:10:42 +0300662 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000663 * @return void
Derek Jones32bf1862010-03-02 13:46:07 -0600664 */
Andrey Andreevcce91802012-06-12 13:25:31 +0300665 public function add_package_path($path, $view_cascade = TRUE)
Derek Jones32bf1862010-03-02 13:46:07 -0600666 {
Pascal Kriete6b6c2742010-11-09 13:12:22 -0500667 $path = rtrim($path, '/').'/';
David Behlercda768a2011-08-14 23:52:48 +0200668
Derek Jones32bf1862010-03-02 13:46:07 -0600669 array_unshift($this->_ci_library_paths, $path);
670 array_unshift($this->_ci_model_paths, $path);
671 array_unshift($this->_ci_helper_paths, $path);
Barry Mienydd671972010-10-04 16:33:58 +0200672
Greg Akerf5c84022011-04-19 17:13:03 -0500673 $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths;
674
Derek Jones32bf1862010-03-02 13:46:07 -0600675 // Add config file path
676 $config =& $this->_ci_get_component('config');
Korri3684d342012-04-17 00:35:08 -0400677 array_push($config->_config_paths, $path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000678 }
679
680 // --------------------------------------------------------------------
Derek Jones32bf1862010-03-02 13:46:07 -0600681
682 /**
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000683 * Get Package Paths
684 *
685 * Return a list of all package paths, by default it will ignore BASEPATH.
686 *
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000687 * @param string
688 * @return void
689 */
Greg Akerf5c84022011-04-19 17:13:03 -0500690 public function get_package_paths($include_base = FALSE)
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000691 {
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300692 return ($include_base === TRUE) ? $this->_ci_library_paths : $this->_ci_model_paths;
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000693 }
694
695 // --------------------------------------------------------------------
696
697 /**
Derek Jones32bf1862010-03-02 13:46:07 -0600698 * Remove Package Path
699 *
700 * Remove a path from the library, model, and helper path arrays if it exists
701 * If no path is provided, the most recently added path is removed.
702 *
Andrey Andreev94af3552012-03-26 23:10:42 +0300703 * @param string
David Behlercda768a2011-08-14 23:52:48 +0200704 * @param bool
Andrey Andreev94af3552012-03-26 23:10:42 +0300705 * @return void
Derek Jones32bf1862010-03-02 13:46:07 -0600706 */
Greg Akerf5c84022011-04-19 17:13:03 -0500707 public function remove_package_path($path = '', $remove_config_path = TRUE)
Derek Jones32bf1862010-03-02 13:46:07 -0600708 {
709 $config =& $this->_ci_get_component('config');
Barry Mienydd671972010-10-04 16:33:58 +0200710
Alex Bilbieed944a32012-06-02 11:07:47 +0100711 if ($path === '')
Derek Jones32bf1862010-03-02 13:46:07 -0600712 {
Andrey Andreevd7297352012-01-07 22:53:14 +0200713 array_shift($this->_ci_library_paths);
714 array_shift($this->_ci_model_paths);
715 array_shift($this->_ci_helper_paths);
716 array_shift($this->_ci_view_paths);
Korri3684d342012-04-17 00:35:08 -0400717 array_pop($config->_config_paths);
Derek Jones32bf1862010-03-02 13:46:07 -0600718 }
719 else
720 {
Pascal Kriete6b6c2742010-11-09 13:12:22 -0500721 $path = rtrim($path, '/').'/';
Derek Jones32bf1862010-03-02 13:46:07 -0600722 foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var)
723 {
724 if (($key = array_search($path, $this->{$var})) !== FALSE)
725 {
726 unset($this->{$var}[$key]);
727 }
728 }
David Behlercda768a2011-08-14 23:52:48 +0200729
Greg Akerf5c84022011-04-19 17:13:03 -0500730 if (isset($this->_ci_view_paths[$path.'views/']))
731 {
732 unset($this->_ci_view_paths[$path.'views/']);
733 }
Barry Mienydd671972010-10-04 16:33:58 +0200734
Derek Jones32bf1862010-03-02 13:46:07 -0600735 if (($key = array_search($path, $config->_config_paths)) !== FALSE)
736 {
737 unset($config->_config_paths[$key]);
738 }
739 }
Barry Mienydd671972010-10-04 16:33:58 +0200740
Derek Jones32bf1862010-03-02 13:46:07 -0600741 // make sure the application default paths are still in the array
742 $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH)));
743 $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH)));
744 $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH)));
Greg Akerf5c84022011-04-19 17:13:03 -0500745 $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE));
Derek Jones32bf1862010-03-02 13:46:07 -0600746 $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH)));
747 }
748
749 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200750
Derek Allard2067d1a2008-11-13 22:59:24 +0000751 /**
752 * Loader
753 *
754 * This function is used to load views and files.
755 * Variables are prefixed with _ci_ to avoid symbol collision with
756 * variables made available to view files
757 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000758 * @param array
759 * @return void
760 */
Greg Akerf5c84022011-04-19 17:13:03 -0500761 protected function _ci_load($_ci_data)
Derek Allard2067d1a2008-11-13 22:59:24 +0000762 {
763 // Set the default data variables
764 foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val)
765 {
Andrey Andreev94af3552012-03-26 23:10:42 +0300766 $$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000767 }
David Behlercda768a2011-08-14 23:52:48 +0200768
Greg Akerf5c84022011-04-19 17:13:03 -0500769 $file_exists = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000770
771 // Set the path to the requested file
Alex Bilbie40bd2a72012-06-02 16:04:15 +0100772 if (is_string($_ci_path) && $_ci_path !== '')
Greg Aker8807be32011-04-21 13:06:15 -0500773 {
774 $_ci_x = explode('/', $_ci_path);
775 $_ci_file = end($_ci_x);
776 }
777 else
Derek Allard2067d1a2008-11-13 22:59:24 +0000778 {
779 $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
Alex Bilbieed944a32012-06-02 11:07:47 +0100780 $_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view;
Greg Akerf5c84022011-04-19 17:13:03 -0500781
Joe McFrederick64f470b2012-08-18 12:29:56 -0400782 foreach ($this->_ci_view_paths as $_ci_view_file => $cascade)
Greg Akerf5c84022011-04-19 17:13:03 -0500783 {
Joe McFrederick64f470b2012-08-18 12:29:56 -0400784 if (file_exists($_ci_view_file.$_ci_file))
Greg Akerf5c84022011-04-19 17:13:03 -0500785 {
Joe McFrederick64f470b2012-08-18 12:29:56 -0400786 $_ci_path = $_ci_view_file.$_ci_file;
Greg Akerf5c84022011-04-19 17:13:03 -0500787 $file_exists = TRUE;
788 break;
789 }
David Behlercda768a2011-08-14 23:52:48 +0200790
Greg Akerf5c84022011-04-19 17:13:03 -0500791 if ( ! $cascade)
792 {
793 break;
David Behlercda768a2011-08-14 23:52:48 +0200794 }
Greg Akerf5c84022011-04-19 17:13:03 -0500795 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000796 }
Barry Mienydd671972010-10-04 16:33:58 +0200797
Greg Akerf5c84022011-04-19 17:13:03 -0500798 if ( ! $file_exists && ! file_exists($_ci_path))
Derek Allard2067d1a2008-11-13 22:59:24 +0000799 {
800 show_error('Unable to load the requested file: '.$_ci_file);
801 }
Barry Mienydd671972010-10-04 16:33:58 +0200802
Derek Allard2067d1a2008-11-13 22:59:24 +0000803 // This allows anything loaded using $this->load (views, files, etc.)
804 // to become accessible from within the Controller and Model functions.
Pascal Kriete89ace432010-11-10 15:49:10 -0500805 $_ci_CI =& get_instance();
806 foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
Derek Allard2067d1a2008-11-13 22:59:24 +0000807 {
Pascal Kriete89ace432010-11-10 15:49:10 -0500808 if ( ! isset($this->$_ci_key))
Derek Allard2067d1a2008-11-13 22:59:24 +0000809 {
Pascal Kriete89ace432010-11-10 15:49:10 -0500810 $this->$_ci_key =& $_ci_CI->$_ci_key;
Derek Allard2067d1a2008-11-13 22:59:24 +0000811 }
812 }
813
814 /*
815 * Extract and cache variables
816 *
vlakoff02506182012-07-03 07:28:50 +0200817 * You can either set variables using the dedicated $this->load->vars()
Derek Allard2067d1a2008-11-13 22:59:24 +0000818 * function or via the second parameter of this function. We'll merge
819 * the two types and cache them so that views that are embedded within
820 * other views can have access to these variables.
Barry Mienydd671972010-10-04 16:33:58 +0200821 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000822 if (is_array($_ci_vars))
823 {
824 $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
825 }
826 extract($this->_ci_cached_vars);
Barry Mienydd671972010-10-04 16:33:58 +0200827
Derek Allard2067d1a2008-11-13 22:59:24 +0000828 /*
829 * Buffer the output
830 *
831 * We buffer the output for two reasons:
832 * 1. Speed. You get a significant speed boost.
Andrey Andreevd7297352012-01-07 22:53:14 +0200833 * 2. So that the final rendered template can be post-processed by
dchill425628ba02012-08-08 12:05:45 -0400834 * the output class. Why do we need post processing? For one thing,
835 * in order to show the elapsed page load time. Unless we can
836 * intercept the content right before it's sent to the browser and
837 * then stop the timer it won't be accurate.
Derek Allard2067d1a2008-11-13 22:59:24 +0000838 */
839 ob_start();
Barry Mienydd671972010-10-04 16:33:58 +0200840
Derek Allard2067d1a2008-11-13 22:59:24 +0000841 // If the PHP installation does not support short tags we'll
842 // do a little string replacement, changing the short tags
843 // to standard PHP echo statements.
Alex Bilbieed944a32012-06-02 11:07:47 +0100844 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 +0000845 {
Andrey Andreevd47baab2012-01-09 16:56:46 +0200846 echo eval('?>'.preg_replace('/;*\s*\?>/', '; ?>', str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000847 }
848 else
849 {
850 include($_ci_path); // include() vs include_once() allows for multiple views with the same name
851 }
Barry Mienydd671972010-10-04 16:33:58 +0200852
Derek Allard2067d1a2008-11-13 22:59:24 +0000853 log_message('debug', 'File loaded: '.$_ci_path);
Barry Mienydd671972010-10-04 16:33:58 +0200854
Derek Allard2067d1a2008-11-13 22:59:24 +0000855 // Return the file data if requested
856 if ($_ci_return === TRUE)
Barry Mienydd671972010-10-04 16:33:58 +0200857 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000858 $buffer = ob_get_contents();
859 @ob_end_clean();
860 return $buffer;
861 }
862
863 /*
864 * Flush the buffer... or buff the flusher?
865 *
866 * In order to permit views to be nested within
867 * other views, we need to flush the content back out whenever
868 * we are beyond the first level of output buffering so that
869 * it can be seen and included properly by the first included
870 * template and any subsequent ones. Oy!
Barry Mienydd671972010-10-04 16:33:58 +0200871 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000872 if (ob_get_level() > $this->_ci_ob_level + 1)
873 {
874 ob_end_flush();
875 }
876 else
877 {
Greg Aker22f1a632010-11-10 15:34:35 -0600878 $_ci_CI->output->append_output(ob_get_contents());
Derek Allard2067d1a2008-11-13 22:59:24 +0000879 @ob_end_clean();
880 }
881 }
882
883 // --------------------------------------------------------------------
884
885 /**
886 * Load class
887 *
888 * This function loads the requested class.
889 *
Barry Mienydd671972010-10-04 16:33:58 +0200890 * @param string the item that is being loaded
Derek Allard2067d1a2008-11-13 22:59:24 +0000891 * @param mixed any additional parameters
892 * @param string an optional object name
Barry Mienydd671972010-10-04 16:33:58 +0200893 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000894 */
Greg Akerf5c84022011-04-19 17:13:03 -0500895 protected function _ci_load_class($class, $params = NULL, $object_name = NULL)
Barry Mienydd671972010-10-04 16:33:58 +0200896 {
897 // Get the class name, and while we're at it trim any slashes.
898 // The directory path can be included as part of the class name,
Derek Allard2067d1a2008-11-13 22:59:24 +0000899 // but we don't want a leading slash
Greg Aker3a746652011-04-19 10:59:47 -0500900 $class = str_replace('.php', '', trim($class, '/'));
Barry Mienydd671972010-10-04 16:33:58 +0200901
Derek Allard2067d1a2008-11-13 22:59:24 +0000902 // Was the path included with the class name?
903 // We look for a slash to determine this
904 $subdir = '';
Derek Jones32bf1862010-03-02 13:46:07 -0600905 if (($last_slash = strrpos($class, '/')) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000906 {
Derek Jones32bf1862010-03-02 13:46:07 -0600907 // Extract the path
Andrey Andreevd7297352012-01-07 22:53:14 +0200908 $subdir = substr($class, 0, ++$last_slash);
Barry Mienydd671972010-10-04 16:33:58 +0200909
Derek Jones32bf1862010-03-02 13:46:07 -0600910 // Get the filename from the path
Andrey Andreevd7297352012-01-07 22:53:14 +0200911 $class = substr($class, $last_slash);
dchill425628ba02012-08-08 12:05:45 -0400912
913 // Check for match and driver base class
dchill42aee92652012-08-26 21:45:35 -0400914 if (strtolower(trim($subdir, '/')) == strtolower($class) && ! class_exists('CI_Driver_Library'))
dchill425628ba02012-08-08 12:05:45 -0400915 {
916 // We aren't instantiating an object here, just making the base class available
917 require BASEPATH.'libraries/Driver.php';
918 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000919 }
920
921 // We'll test for both lowercase and capitalized versions of the file name
922 foreach (array(ucfirst($class), strtolower($class)) as $class)
923 {
Greg Aker3a746652011-04-19 10:59:47 -0500924 $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php';
Derek Allard2067d1a2008-11-13 22:59:24 +0000925
Barry Mienydd671972010-10-04 16:33:58 +0200926 // Is this a class extension request?
Derek Allard2067d1a2008-11-13 22:59:24 +0000927 if (file_exists($subclass))
928 {
Greg Aker3a746652011-04-19 10:59:47 -0500929 $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php';
Barry Mienydd671972010-10-04 16:33:58 +0200930
Derek Allard2067d1a2008-11-13 22:59:24 +0000931 if ( ! file_exists($baseclass))
932 {
Andrey Andreevd7297352012-01-07 22:53:14 +0200933 log_message('error', 'Unable to load the requested class: '.$class);
934 show_error('Unable to load the requested class: '.$class);
Derek Allard2067d1a2008-11-13 22:59:24 +0000935 }
936
Andrey Andreevd7297352012-01-07 22:53:14 +0200937 // Safety: Was the class already loaded by a previous call?
Derek Allard2067d1a2008-11-13 22:59:24 +0000938 if (in_array($subclass, $this->_ci_loaded_files))
939 {
940 // Before we deem this to be a duplicate request, let's see
Andrey Andreevd7297352012-01-07 22:53:14 +0200941 // if a custom object name is being supplied. If so, we'll
Derek Allard2067d1a2008-11-13 22:59:24 +0000942 // return a new instance of the object
943 if ( ! is_null($object_name))
944 {
945 $CI =& get_instance();
946 if ( ! isset($CI->$object_name))
947 {
Barry Mienydd671972010-10-04 16:33:58 +0200948 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000949 }
950 }
Barry Mienydd671972010-10-04 16:33:58 +0200951
Derek Allard2067d1a2008-11-13 22:59:24 +0000952 $is_duplicate = TRUE;
Andrey Andreevd7297352012-01-07 22:53:14 +0200953 log_message('debug', $class.' class already loaded. Second attempt ignored.');
Derek Allard2067d1a2008-11-13 22:59:24 +0000954 return;
955 }
Barry Mienydd671972010-10-04 16:33:58 +0200956
957 include_once($baseclass);
Derek Allard2067d1a2008-11-13 22:59:24 +0000958 include_once($subclass);
959 $this->_ci_loaded_files[] = $subclass;
Barry Mienydd671972010-10-04 16:33:58 +0200960
961 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000962 }
Barry Mienydd671972010-10-04 16:33:58 +0200963
Derek Allard2067d1a2008-11-13 22:59:24 +0000964 // Lets search for the requested library file and load it.
Derek Jones32bf1862010-03-02 13:46:07 -0600965 $is_duplicate = FALSE;
966 foreach ($this->_ci_library_paths as $path)
Derek Allard2067d1a2008-11-13 22:59:24 +0000967 {
Greg Aker3a746652011-04-19 10:59:47 -0500968 $filepath = $path.'libraries/'.$subdir.$class.'.php';
Derek Jones32bf1862010-03-02 13:46:07 -0600969
Andrey Andreevd7297352012-01-07 22:53:14 +0200970 // Does the file exist? No? Bummer...
Derek Allard2067d1a2008-11-13 22:59:24 +0000971 if ( ! file_exists($filepath))
972 {
973 continue;
974 }
Barry Mienydd671972010-10-04 16:33:58 +0200975
Andrey Andreevd7297352012-01-07 22:53:14 +0200976 // Safety: Was the class already loaded by a previous call?
Derek Allard2067d1a2008-11-13 22:59:24 +0000977 if (in_array($filepath, $this->_ci_loaded_files))
978 {
979 // Before we deem this to be a duplicate request, let's see
Andrey Andreevd7297352012-01-07 22:53:14 +0200980 // if a custom object name is being supplied. If so, we'll
Derek Allard2067d1a2008-11-13 22:59:24 +0000981 // return a new instance of the object
982 if ( ! is_null($object_name))
983 {
984 $CI =& get_instance();
985 if ( ! isset($CI->$object_name))
986 {
987 return $this->_ci_init_class($class, '', $params, $object_name);
988 }
989 }
Barry Mienydd671972010-10-04 16:33:58 +0200990
Derek Allard2067d1a2008-11-13 22:59:24 +0000991 $is_duplicate = TRUE;
Andrey Andreevd7297352012-01-07 22:53:14 +0200992 log_message('debug', $class.' class already loaded. Second attempt ignored.');
Derek Allard2067d1a2008-11-13 22:59:24 +0000993 return;
994 }
Barry Mienydd671972010-10-04 16:33:58 +0200995
Derek Allard2067d1a2008-11-13 22:59:24 +0000996 include_once($filepath);
997 $this->_ci_loaded_files[] = $filepath;
Barry Mienydd671972010-10-04 16:33:58 +0200998 return $this->_ci_init_class($class, '', $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000999 }
1000 } // END FOREACH
1001
Andrey Andreevd7297352012-01-07 22:53:14 +02001002 // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified?
Alex Bilbieed944a32012-06-02 11:07:47 +01001003 if ($subdir === '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001004 {
1005 $path = strtolower($class).'/'.$class;
dchill420fc3be52012-08-27 20:54:23 -04001006 return $this->_ci_load_class($path, $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +00001007 }
Andrey Andreev5fd3ae82012-10-24 14:55:35 +03001008 elseif (ucfirst($subdir) != $subdir)
dchill42aee92652012-08-26 21:45:35 -04001009 {
1010 // Lowercase subdir failed - retry capitalized
1011 $path = ucfirst($subdir).$class;
dchill420fc3be52012-08-27 20:54:23 -04001012 return $this->_ci_load_class($path, $params, $object_name);
dchill42aee92652012-08-26 21:45:35 -04001013 }
Barry Mienydd671972010-10-04 16:33:58 +02001014
Derek Allard2067d1a2008-11-13 22:59:24 +00001015 // If we got this far we were unable to find the requested class.
1016 // We do not issue errors if the load call failed due to a duplicate request
Alex Bilbieed944a32012-06-02 11:07:47 +01001017 if ($is_duplicate === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001018 {
Andrey Andreevd7297352012-01-07 22:53:14 +02001019 log_message('error', 'Unable to load the requested class: '.$class);
1020 show_error('Unable to load the requested class: '.$class);
Derek Allard2067d1a2008-11-13 22:59:24 +00001021 }
1022 }
Barry Mienydd671972010-10-04 16:33:58 +02001023
Derek Allard2067d1a2008-11-13 22:59:24 +00001024 // --------------------------------------------------------------------
1025
1026 /**
1027 * Instantiates a class
1028 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001029 * @param string
1030 * @param string
David Behlercda768a2011-08-14 23:52:48 +02001031 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +00001032 * @param string an optional object name
Andrey Andreev94af3552012-03-26 23:10:42 +03001033 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +00001034 */
Greg Aker0c9ee4a2011-04-20 09:40:17 -05001035 protected function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL)
Barry Mienydd671972010-10-04 16:33:58 +02001036 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001037 // Is there an associated config file for this class? Note: these should always be lowercase
Derek Allard2067d1a2008-11-13 22:59:24 +00001038 if ($config === NULL)
1039 {
Eric Barnes5e16ec62011-01-04 17:25:23 -05001040 // Fetch the config paths containing any package paths
1041 $config_component = $this->_ci_get_component('config');
1042
1043 if (is_array($config_component->_config_paths))
Derek Allard2067d1a2008-11-13 22:59:24 +00001044 {
Eric Barnes5e16ec62011-01-04 17:25:23 -05001045 // Break on the first found file, thus package files
1046 // are not overridden by default paths
1047 foreach ($config_component->_config_paths as $path)
1048 {
1049 // We test for both uppercase and lowercase, for servers that
joelcox1bfd9fa2011-01-16 18:49:39 +01001050 // are case-sensitive with regard to file names. Check for environment
1051 // first, global next
Andrey Andreev94af3552012-03-26 23:10:42 +03001052 if (defined('ENVIRONMENT') && file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'))
joelcox1bfd9fa2011-01-16 18:49:39 +01001053 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001054 include($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php');
joelcox1bfd9fa2011-01-16 18:49:39 +01001055 break;
1056 }
Andrey Andreev94af3552012-03-26 23:10:42 +03001057 elseif (defined('ENVIRONMENT') && file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'))
joelcox1bfd9fa2011-01-16 18:49:39 +01001058 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001059 include($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php');
joelcox1bfd9fa2011-01-16 18:49:39 +01001060 break;
1061 }
Andrey Andreev94af3552012-03-26 23:10:42 +03001062 elseif (file_exists($path.'config/'.strtolower($class).'.php'))
Eric Barnes5e16ec62011-01-04 17:25:23 -05001063 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001064 include($path.'config/'.strtolower($class).'.php');
Eric Barnes5e16ec62011-01-04 17:25:23 -05001065 break;
1066 }
Andrey Andreev94af3552012-03-26 23:10:42 +03001067 elseif (file_exists($path.'config/'.ucfirst(strtolower($class)).'.php'))
Eric Barnes5e16ec62011-01-04 17:25:23 -05001068 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001069 include($path.'config/'.ucfirst(strtolower($class)).'.php');
Eric Barnes5e16ec62011-01-04 17:25:23 -05001070 break;
1071 }
1072 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001073 }
1074 }
Barry Mienydd671972010-10-04 16:33:58 +02001075
Alex Bilbieed944a32012-06-02 11:07:47 +01001076 if ($prefix === '')
Barry Mienydd671972010-10-04 16:33:58 +02001077 {
1078 if (class_exists('CI_'.$class))
Derek Allard2067d1a2008-11-13 22:59:24 +00001079 {
1080 $name = 'CI_'.$class;
1081 }
Barry Mienydd671972010-10-04 16:33:58 +02001082 elseif (class_exists(config_item('subclass_prefix').$class))
Derek Allard2067d1a2008-11-13 22:59:24 +00001083 {
1084 $name = config_item('subclass_prefix').$class;
1085 }
1086 else
1087 {
1088 $name = $class;
1089 }
1090 }
1091 else
1092 {
1093 $name = $prefix.$class;
1094 }
Barry Mienydd671972010-10-04 16:33:58 +02001095
Derek Allard2067d1a2008-11-13 22:59:24 +00001096 // Is the class name valid?
1097 if ( ! class_exists($name))
1098 {
Andrey Andreevd7297352012-01-07 22:53:14 +02001099 log_message('error', 'Non-existent class: '.$name);
jonnueee2df62012-07-16 13:06:16 +01001100 show_error('Non-existent class: '.$name);
Derek Allard2067d1a2008-11-13 22:59:24 +00001101 }
Barry Mienydd671972010-10-04 16:33:58 +02001102
Derek Allard2067d1a2008-11-13 22:59:24 +00001103 // Set the variable name we will assign the class to
Andrey Andreevd7297352012-01-07 22:53:14 +02001104 // Was a custom class name supplied? If so we'll use it
Derek Allard2067d1a2008-11-13 22:59:24 +00001105 $class = strtolower($class);
Barry Mienydd671972010-10-04 16:33:58 +02001106
Derek Allard2067d1a2008-11-13 22:59:24 +00001107 if (is_null($object_name))
1108 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001109 $classvar = isset($this->_ci_varmap[$class]) ? $this->_ci_varmap[$class] : $class;
Derek Allard2067d1a2008-11-13 22:59:24 +00001110 }
1111 else
1112 {
1113 $classvar = $object_name;
1114 }
1115
Barry Mienydd671972010-10-04 16:33:58 +02001116 // Save the class name and object name
Derek Allard2067d1a2008-11-13 22:59:24 +00001117 $this->_ci_classes[$class] = $classvar;
1118
Barry Mienydd671972010-10-04 16:33:58 +02001119 // Instantiate the class
Derek Allard2067d1a2008-11-13 22:59:24 +00001120 $CI =& get_instance();
1121 if ($config !== NULL)
1122 {
1123 $CI->$classvar = new $name($config);
1124 }
1125 else
Barry Mienydd671972010-10-04 16:33:58 +02001126 {
Andrey Andreeva11b16b2012-03-28 12:22:04 +03001127 $CI->$classvar = new $name();
Barry Mienydd671972010-10-04 16:33:58 +02001128 }
1129 }
1130
Derek Allard2067d1a2008-11-13 22:59:24 +00001131 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001132
Derek Allard2067d1a2008-11-13 22:59:24 +00001133 /**
1134 * Autoloader
1135 *
1136 * The config/autoload.php file contains an array that permits sub-systems,
Derek Jonesc6da5032010-03-09 20:44:27 -06001137 * libraries, and helpers to be loaded automatically.
Derek Allard2067d1a2008-11-13 22:59:24 +00001138 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001139 * @return void
1140 */
Shane Pearson665baec2011-08-22 18:52:19 -05001141 protected function _ci_autoloader()
Barry Mienydd671972010-10-04 16:33:58 +02001142 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001143 if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'))
bubbafoley0ea04142011-03-17 14:55:41 -05001144 {
Shane Pearson6adfe632011-08-10 16:42:53 -05001145 include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php');
bubbafoley0ea04142011-03-17 14:55:41 -05001146 }
1147 else
1148 {
Shane Pearson6adfe632011-08-10 16:42:53 -05001149 include(APPPATH.'config/autoload.php');
bubbafoley0ea04142011-03-17 14:55:41 -05001150 }
Barry Mienydd671972010-10-04 16:33:58 +02001151
Derek Allard2067d1a2008-11-13 22:59:24 +00001152 if ( ! isset($autoload))
1153 {
1154 return FALSE;
1155 }
Barry Mienydd671972010-10-04 16:33:58 +02001156
Phil Sturgeon9730c752010-12-15 10:50:15 +00001157 // Autoload packages
1158 if (isset($autoload['packages']))
1159 {
1160 foreach ($autoload['packages'] as $package_path)
1161 {
1162 $this->add_package_path($package_path);
1163 }
1164 }
1165
Derek Allard2067d1a2008-11-13 22:59:24 +00001166 // Load any custom config file
1167 if (count($autoload['config']) > 0)
Barry Mienydd671972010-10-04 16:33:58 +02001168 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001169 $CI =& get_instance();
1170 foreach ($autoload['config'] as $key => $val)
1171 {
1172 $CI->config->load($val);
1173 }
Barry Mienydd671972010-10-04 16:33:58 +02001174 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001175
Derek Jonesc6da5032010-03-09 20:44:27 -06001176 // Autoload helpers and languages
1177 foreach (array('helper', 'language') as $type)
Barry Mienydd671972010-10-04 16:33:58 +02001178 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001179 if (isset($autoload[$type]) && count($autoload[$type]) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001180 {
1181 $this->$type($autoload[$type]);
Barry Mienydd671972010-10-04 16:33:58 +02001182 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001183 }
1184
Derek Allard2067d1a2008-11-13 22:59:24 +00001185 // Load libraries
Andrey Andreev94af3552012-03-26 23:10:42 +03001186 if (isset($autoload['libraries']) && count($autoload['libraries']) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001187 {
1188 // Load the database driver.
1189 if (in_array('database', $autoload['libraries']))
1190 {
1191 $this->database();
1192 $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
1193 }
Barry Mienydd671972010-10-04 16:33:58 +02001194
Derek Allard2067d1a2008-11-13 22:59:24 +00001195 // Load all other libraries
1196 foreach ($autoload['libraries'] as $item)
1197 {
1198 $this->library($item);
1199 }
Barry Mienydd671972010-10-04 16:33:58 +02001200 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001201
Darren Hillc4e266b2011-08-30 15:40:27 -04001202 // Autoload drivers
1203 if (isset($autoload['drivers']))
1204 {
Darren Hillca3be1d2011-08-31 08:31:18 -04001205 foreach ($autoload['drivers'] as $item)
1206 {
1207 $this->driver($item);
1208 }
Darren Hillc4e266b2011-08-30 15:40:27 -04001209 }
1210
Derek Allard2067d1a2008-11-13 22:59:24 +00001211 // Autoload models
1212 if (isset($autoload['model']))
1213 {
1214 $this->model($autoload['model']);
1215 }
Barry Mienydd671972010-10-04 16:33:58 +02001216 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001217
1218 // --------------------------------------------------------------------
1219
1220 /**
1221 * Object to Array
1222 *
1223 * Takes an object as input and converts the class variables to array key/vals
1224 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001225 * @param object
1226 * @return array
1227 */
Greg Akerf5c84022011-04-19 17:13:03 -05001228 protected function _ci_object_to_array($object)
Derek Allard2067d1a2008-11-13 22:59:24 +00001229 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001230 return is_object($object) ? get_object_vars($object) : $object;
Derek Allard2067d1a2008-11-13 22:59:24 +00001231 }
1232
1233 // --------------------------------------------------------------------
1234
1235 /**
Derek Jones32bf1862010-03-02 13:46:07 -06001236 * Get a reference to a specific library or model
1237 *
David Behlercda768a2011-08-14 23:52:48 +02001238 * @param string
Derek Jones32bf1862010-03-02 13:46:07 -06001239 * @return bool
1240 */
Greg Akerf5c84022011-04-19 17:13:03 -05001241 protected function &_ci_get_component($component)
Derek Jones32bf1862010-03-02 13:46:07 -06001242 {
Pascal Kriete89ace432010-11-10 15:49:10 -05001243 $CI =& get_instance();
1244 return $CI->$component;
Derek Jones32bf1862010-03-02 13:46:07 -06001245 }
1246
1247 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001248
Derek Jones32bf1862010-03-02 13:46:07 -06001249 /**
1250 * Prep filename
1251 *
1252 * This function preps the name of various items to make loading them more reliable.
1253 *
Derek Jones32bf1862010-03-02 13:46:07 -06001254 * @param mixed
David Behlercda768a2011-08-14 23:52:48 +02001255 * @param string
Derek Jones32bf1862010-03-02 13:46:07 -06001256 * @return array
1257 */
Greg Akerf5c84022011-04-19 17:13:03 -05001258 protected function _ci_prep_filename($filename, $extension)
Derek Jones32bf1862010-03-02 13:46:07 -06001259 {
1260 if ( ! is_array($filename))
Barry Mienydd671972010-10-04 16:33:58 +02001261 {
Andrey Andreevd47baab2012-01-09 16:56:46 +02001262 return array(strtolower(str_replace(array($extension, '.php'), '', $filename).$extension));
Derek Jones32bf1862010-03-02 13:46:07 -06001263 }
1264 else
1265 {
1266 foreach ($filename as $key => $val)
1267 {
Andrey Andreevd47baab2012-01-09 16:56:46 +02001268 $filename[$key] = strtolower(str_replace(array($extension, '.php'), '', $val).$extension);
Derek Jones32bf1862010-03-02 13:46:07 -06001269 }
Barry Mienydd671972010-10-04 16:33:58 +02001270
Derek Jones32bf1862010-03-02 13:46:07 -06001271 return $filename;
1272 }
1273 }
Andrey Andreev94af3552012-03-26 23:10:42 +03001274
Derek Allard2067d1a2008-11-13 22:59:24 +00001275}
1276
1277/* End of file Loader.php */
Andrey Andreev9438e262012-10-05 13:16:27 +03001278/* Location: ./system/core/Loader.php */