summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rw-r--r--system/database/DB.php19
-rw-r--r--system/database/DB_driver.php19
-rw-r--r--system/libraries/Controller.php2
-rw-r--r--system/libraries/Loader.php173
-rw-r--r--system/libraries/Model.php28
5 files changed, 74 insertions, 167 deletions
diff --git a/system/database/DB.php b/system/database/DB.php
index 62237440f..a148c9ffe 100644
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -22,14 +22,8 @@
* @author Rick Ellis
* @link http://www.codeigniter.com/user_guide/database/
*/
-function DB($params = '', $return = FALSE, $active_record = FALSE)
+function DB($params = '', $active_record = FALSE)
{
- // Do we even need to load the database class?
- if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE)
- {
- return FALSE;
- }
-
// Load the DB config file if a DSN string wasn't passed
if (is_string($params) AND strpos($params, '://') === FALSE)
{
@@ -84,15 +78,8 @@ function DB($params = '', $return = FALSE, $active_record = FALSE)
// Instantiate the DB adapter
$driver = 'CI_DB_'.$params['dbdriver'].'_driver';
- $DB = new $driver($params);
-
- if ($return === TRUE)
- {
- return $DB;
- }
-
- $CI =& get_instance();
- $CI->db =& $DB;
+ $DB = new $driver($params);
+ return $DB;
}
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index a4131fd73..848d4f1c6 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -155,26 +155,7 @@ class CI_DB_driver {
}
}
}
-
- // --------------------------------------------------------------------
-
- /**
- * Load the Utilities Class
- *
- * @access public
- * @return string
- */
- function load_utilities()
- {
- require_once(BASEPATH.'database/DB_utility'.EXT);
- require_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_utility'.EXT);
- $class = 'CI_DB_'.$this->dbdriver.'_utility';
- $CI =& get_instance();
- $CI->dbutil = new $class();
- $CI->_ci_assign_to_models();
- }
-
// --------------------------------------------------------------------
/**
diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php
index 88ab46164..0bbc7773e 100644
--- a/system/libraries/Controller.php
+++ b/system/libraries/Controller.php
@@ -88,7 +88,7 @@ class Controller extends CI_Base {
$this->_ci_autoloader();
}
}
-
+
// --------------------------------------------------------------------
/**
diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php
index 7a6637ac0..1f6a8bce1 100644
--- a/system/libraries/Loader.php
+++ b/system/libraries/Loader.php
@@ -119,20 +119,10 @@ class CI_Loader {
return;
}
- if ($this->_ci_is_instance())
- {
- $CI =& get_instance();
- if (isset($CI->$name))
- {
- show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
- }
- }
- else
+ $CI =& get_instance();
+ if (isset($CI->$name))
{
- if (isset($this->$name))
- {
- show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
- }
+ show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
}
$model = strtolower($model);
@@ -147,14 +137,7 @@ class CI_Loader {
if ($db_conn === TRUE)
$db_conn = '';
- if ($this->_ci_is_instance())
- {
- $CI->load->database($db_conn, FALSE, TRUE);
- }
- else
- {
- $this->database($db_conn, FALSE, TRUE);
- }
+ $CI->load->database($db_conn, FALSE, TRUE);
}
if ( ! class_exists('Model'))
@@ -166,28 +149,12 @@ class CI_Loader {
$model = ucfirst($model);
- if ($this->_ci_is_instance())
- {
- $CI->$name = new $model();
- foreach (get_object_vars($CI) as $key => $var)
- {
- $CI->$name->$key =& $CI->$key;
- }
- }
- else
- {
- $this->$name = new $model();
- foreach (get_object_vars($this) as $key => $var)
- {
- $this->$name->$key =& $this->$key;
- }
- }
+ $CI->$name = new $model();
+ $CI->$name->_assign_libraries();
- $this->_ci_models[] = $name;
- $this->_ci_assign_to_models();
+ $this->_ci_models[] = $name;
}
-
-
+
// --------------------------------------------------------------------
/**
@@ -201,19 +168,49 @@ class CI_Loader {
*/
function database($params = '', $return = FALSE, $active_record = FALSE)
{
+ // Do we even need to load the database class?
+ if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE)
+ {
+ return FALSE;
+ }
+
require_once(BASEPATH.'database/DB'.EXT);
if ($return === TRUE)
{
- return DB($params, $return, $active_record);
+ return DB($params, $active_record);
}
- else
+
+ $CI =& get_instance();
+ $CI->db =& DB($params, $active_record);
+ $this->_ci_assign_to_models();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Load the Utilities Class
+ *
+ * @access public
+ * @return string
+ */
+ function dbutil()
+ {
+ if ( ! class_exists('CI_DB'))
{
- DB($params, $return, $active_record);
- $this->_ci_assign_to_models();
+ $this->database();
}
- }
+ $CI =& get_instance();
+
+ require_once(BASEPATH.'database/DB_utility'.EXT);
+ require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT);
+ $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
+
+ $CI->dbutil = new $class();
+ $CI->load->_ci_assign_to_models();
+ }
+
// --------------------------------------------------------------------
/**
@@ -467,15 +464,8 @@ class CI_Loader {
*/
function language($file = '', $lang = '', $return = FALSE)
{
- if ($this->_ci_is_instance())
- {
- $CI =& get_instance();
- return $CI->lang->load($file, $lang, $return);
- }
- else
- {
- return $this->lang->load($file, $lang, $return);
- }
+ $CI =& get_instance();
+ return $CI->lang->load($file, $lang, $return);
}
// --------------------------------------------------------------------
@@ -489,15 +479,8 @@ class CI_Loader {
*/
function config($file = '')
{
- if ($this->_ci_is_instance())
- {
- $CI =& get_instance();
- $CI->config->load($file);
- }
- else
- {
- $this->config->load($file);
- }
+ $CI =& get_instance();
+ $CI->config->load($file);
}
// --------------------------------------------------------------------
@@ -524,17 +507,9 @@ class CI_Loader {
show_error('You must include the name of the table you would like access when you initialize scaffolding');
}
- if ($this->_ci_is_instance())
- {
- $CI =& get_instance();
- $CI->_ci_scaffolding = TRUE;
- $CI->_ci_scaff_table = $table;
- }
- else
- {
- $this->_ci_scaffolding = TRUE;
- $this->_ci_scaff_table = $table;
- }
+ $CI =& get_instance();
+ $CI->_ci_scaffolding = TRUE;
+ $CI->_ci_scaff_table = $table;
}
// --------------------------------------------------------------------
@@ -755,29 +730,15 @@ class CI_Loader {
}
// Instantiate the class
- if ($this->_ci_is_instance())
+ $CI =& get_instance();
+ if ($config !== NULL)
{
- $CI =& get_instance();
- if ($config !== NULL)
- {
- $CI->$classvar = new $name($config);
- }
- else
- {
- $CI->$classvar = new $name;
- }
+ $CI->$classvar = new $name($config);
}
else
- {
- if ($config !== NULL)
- {
- $this->$classvar = new $name($config);
- }
- else
- {
- $this->$classvar = new $name;
- }
- }
+ {
+ $CI->$classvar = new $name;
+ }
}
// --------------------------------------------------------------------
@@ -804,20 +765,10 @@ class CI_Loader {
// Load any custome config file
if (count($autoload['config']) > 0)
{
- if ($this->_ci_is_instance())
- {
- $CI =& get_instance();
- foreach ($autoload['config'] as $key => $val)
- {
- $CI->config->load($val);
- }
- }
- else
+ $CI =& get_instance();
+ foreach ($autoload['config'] as $key => $val)
{
- foreach ($autoload['config'] as $key => $val)
- {
- $this->config->load($val);
- }
+ $CI->config->load($val);
}
}
@@ -893,14 +844,14 @@ class CI_Loader {
$CI =& get_instance();
foreach ($this->_ci_models as $model)
{
- $CI->$model->_assign_libraries();
+ $CI->$model->_assign_libraries();
}
}
else
- {
+ {
foreach ($this->_ci_models as $model)
{
- $this->$model->_assign_libraries();
+ $this->$model->_assign_libraries();
}
}
}
diff --git a/system/libraries/Model.php b/system/libraries/Model.php
index 48615e07c..017a9c6d8 100644
--- a/system/libraries/Model.php
+++ b/system/libraries/Model.php
@@ -33,10 +33,9 @@ class Model {
*/
function Model()
{
- $this->_assign_libraries(FALSE);
+ $this->_assign_libraries();
log_message('debug', "Model Class Initialized");
}
- // END Model()
/**
* Assign Libraries
@@ -47,26 +46,15 @@ class Model {
*
* @access private
*/
- function _assign_libraries($use_reference = TRUE)
+ function _assign_libraries()
{
- $CI =& get_instance();
- foreach (get_object_vars($CI) as $key => $var)
- {
- if ( ! isset($this->$key))
- {
- if ($use_reference === TRUE)
- {
- $this->$key =& $CI->$key;
- }
- else
- {
- $this->$key = $CI->$key;
- }
- }
- }
-
+ $CI =& get_instance();
+
+ foreach (array_keys(get_object_vars($CI)) as $key)
+ {
+ $this->$key =& $CI->$key;
+ }
}
- // END _assign_libraries()
}
// END Model Class