summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2011-04-06 23:57:43 +0200
committerPhil Sturgeon <email@philsturgeon.co.uk>2011-04-06 23:57:43 +0200
commit05fa61144667c85b0463f7e8baa6af00aa195dc6 (patch)
tree2a611231c945ce7fd5bd021e3491dd973794f58e
parent08b5169a5181706156c9a53229d164d9fa3aea32 (diff)
Made Environment Support optional. Comment out or delete the constant to stop environment checks.
-rw-r--r--index.php3
-rw-r--r--system/core/CodeIgniter.php2
-rw-r--r--system/core/Common.php15
-rw-r--r--system/core/Config.php42
-rw-r--r--system/core/Hooks.php2
-rw-r--r--system/core/Loader.php6
-rw-r--r--system/core/Output.php2
-rw-r--r--system/core/Router.php2
-rw-r--r--system/database/DB.php13
-rw-r--r--system/helpers/download_helper.php2
-rw-r--r--system/helpers/file_helper.php2
-rw-r--r--system/helpers/html_helper.php2
-rw-r--r--system/helpers/smiley_helper.php15
-rw-r--r--system/helpers/text_helper.php2
-rw-r--r--system/libraries/Upload.php2
-rw-r--r--system/libraries/User_agent.php2
-rw-r--r--user_guide/changelog.html1
-rw-r--r--user_guide/database/active_record.html24
18 files changed, 82 insertions, 57 deletions
diff --git a/index.php b/index.php
index 74e3ba32a..6e67c2db5 100644
--- a/index.php
+++ b/index.php
@@ -28,6 +28,8 @@
* By default development will show errors but testing and live will hide them.
*/
+if (defined('ENVIRONMENT'))
+{
switch (ENVIRONMENT)
{
case 'development':
@@ -42,6 +44,7 @@
default:
exit('The application environment is not set correctly.');
}
+}
/*
*---------------------------------------------------------------
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 39a4d7ffd..143faec15 100644
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -53,7 +53,7 @@
* Load the framework constants
* ------------------------------------------------------
*/
- if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT))
+ if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT))
{
require(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT);
}
diff --git a/system/core/Common.php b/system/core/Common.php
index f424a2cc9..d7054ebe6 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -208,19 +208,18 @@
return $_config[0];
}
- $file_path = APPPATH.'config/'.ENVIRONMENT.'/config'.EXT;
+ // Is the config file in the environment folder?
+ if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config'.EXT))
+ {
+ $file_path = APPPATH.'config/config'.EXT;
+ }
// Fetch the config file
if ( ! file_exists($file_path))
{
- $file_path = APPPATH.'config/config'.EXT;
-
- if ( ! file_exists($file_path))
- {
- exit('The configuration file does not exist.');
- }
+ exit('The configuration file does not exist.');
}
-
+
require($file_path);
// Does the $config array exist in the file?
diff --git a/system/core/Config.php b/system/core/Config.php
index a2a7dd564..863c5ef4b 100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -81,29 +81,37 @@ class CI_Config {
function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
$file = ($file == '') ? 'config' : str_replace(EXT, '', $file);
+ $found = FALSE;
$loaded = FALSE;
foreach ($this->_config_paths as $path)
- {
- $file_path = $path.'config/'.ENVIRONMENT.'/'.$file.EXT;
+ {
+ $check_locations = defined('ENVIRONMENT')
+ ? array(ENVIRONMENT.'/'.$file, $file)
+ : array($file);
- if (in_array($file_path, $this->is_loaded, TRUE))
+ foreach ($check_locations as $location)
{
- $loaded = TRUE;
- continue;
- }
+ $file_path = $path.'config/'.$location.EXT;
- if ( ! file_exists($file_path))
- {
- log_message('debug', 'Config for '.ENVIRONMENT.' environment is not found. Trying global config.');
- $file_path = $path.'config/'.$file.EXT;
-
- if ( ! file_exists($file_path))
+ if (in_array($file_path, $this->is_loaded, TRUE))
+ {
+ $loaded = TRUE;
+ continue 2;
+ }
+
+ if (file_exists($file_path))
{
- continue;
+ $found = TRUE;
+ break;
}
}
-
+
+ if ($found === FALSE)
+ {
+ continue;
+ }
+
include($file_path);
if ( ! isset($config) OR ! is_array($config))
@@ -144,9 +152,9 @@ class CI_Config {
{
return FALSE;
}
- show_error('The configuration file '.ENVIRONMENT.'/'.$file.EXT.' and '.$file.EXT.' do not exist.');
+ show_error('The configuration file '.$file.EXT.' does not exist.');
}
-
+
return TRUE;
}
@@ -318,4 +326,4 @@ class CI_Config {
// END CI_Config class
/* End of file Config.php */
-/* Location: ./system/core/Config.php */
+/* Location: ./system/core/Config.php */ \ No newline at end of file
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index d1e5586de..24fa1055b 100644
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
@@ -65,7 +65,7 @@ class CI_Hooks {
// Grab the "hooks" definition file.
// If there are no hooks, we're done.
- if (is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks'.EXT))
+ if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks'.EXT))
{
include(APPPATH.'config/'.ENVIRONMENT.'/hooks'.EXT);
}
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 278a868e6..e75805d0e 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -872,12 +872,12 @@ class CI_Loader {
// We test for both uppercase and lowercase, for servers that
// are case-sensitive with regard to file names. Check for environment
// first, global next
- if (file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).EXT))
+ if (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).EXT))
{
include_once($path .'config/'.ENVIRONMENT.'/'.strtolower($class).EXT);
break;
}
- elseif (file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).EXT))
+ elseif (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).EXT))
{
include_once($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).EXT);
break;
@@ -965,7 +965,7 @@ class CI_Loader {
*/
function _ci_autoloader()
{
- if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload'.EXT))
+ if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload'.EXT))
{
include_once(APPPATH.'config/'.ENVIRONMENT.'/autoload'.EXT);
}
diff --git a/system/core/Output.php b/system/core/Output.php
index 5ec096a47..bcba2577a 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -42,7 +42,7 @@ class CI_Output {
$this->_zlib_oc = @ini_get('zlib.output_compression');
// Get mime types for later
- if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT))
+ if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT))
{
include APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT;
}
diff --git a/system/core/Router.php b/system/core/Router.php
index 2c78efe07..d451aab68 100644
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -87,7 +87,7 @@ class CI_Router {
}
// Load the routes.php file.
- if (is_file(APPPATH.'config/'.ENVIRONMENT.'/routes'.EXT))
+ if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes'.EXT))
{
include(APPPATH.'config/'.ENVIRONMENT.'/routes'.EXT);
}
diff --git a/system/database/DB.php b/system/database/DB.php
index 93ee3922a..8bf1ba8ba 100644
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -27,17 +27,12 @@ function &DB($params = '', $active_record_override = NULL)
// Load the DB config file if a DSN string wasn't passed
if (is_string($params) AND strpos($params, '://') === FALSE)
{
-
- $file_path = APPPATH.'config/'.ENVIRONMENT.'/database'.EXT;
-
- if ( ! file_exists($file_path))
+ // Is the config file in the environment folder?
+ if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database'.EXT))
{
- log_message('debug', 'Database config for '.ENVIRONMENT.' environment is not found. Trying global config.');
- $file_path = APPPATH.'config/database'.EXT;
-
- if ( ! file_exists($file_path))
+ if ( ! file_exists($file_path = APPPATH.'config/database'.EXT))
{
- continue;
+ show_error('The configuration file database'.EXT.' does not exist.');
}
}
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index e537cdeca..f8073d238 100644
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -58,7 +58,7 @@ if ( ! function_exists('force_download'))
$extension = end($x);
// Load the mime types
- if (is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT))
+ if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT))
{
include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT);
}
diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php
index 7a35c3fa1..44344947e 100644
--- a/system/helpers/file_helper.php
+++ b/system/helpers/file_helper.php
@@ -352,7 +352,7 @@ if ( ! function_exists('get_mime_by_extension'))
if ( ! is_array($mimes))
{
- if (is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT))
+ if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT))
{
include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT);
}
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 53fc899a3..c6103ab6f 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -258,7 +258,7 @@ if ( ! function_exists('doctype'))
if ( ! is_array($_doctypes))
{
- if (is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT))
+ if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT))
{
include(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT);
}
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index 6c901515d..a2d1031b3 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -229,26 +229,21 @@ if ( ! function_exists('_get_smiley_array'))
{
function _get_smiley_array()
{
- if ( ! file_exists(APPPATH.'config/smileys'.EXT) AND ! file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT))
- {
- return FALSE;
- }
-
- if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT))
+ if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT))
{
include(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT);
}
- else
+ elseif (file_exists(APPPATH.'config/smileys'.EXT))
{
include(APPPATH.'config/smileys'.EXT);
}
- if ( ! isset($smileys) OR ! is_array($smileys))
+ if (isset($smileys) AND is_array($smileys))
{
- return FALSE;
+ return $smileys;
}
- return $smileys;
+ return FALSE;
}
}
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 664408912..cca093976 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -366,7 +366,7 @@ if ( ! function_exists('convert_accented_characters'))
{
function convert_accented_characters($str)
{
- if (is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars'.EXT))
+ if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars'.EXT))
{
include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars'.EXT);
}
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 5816a5558..3cd2e4fc1 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -951,7 +951,7 @@ class CI_Upload {
if (count($this->mimes) == 0)
{
- if (is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT))
+ if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT))
{
include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT);
}
diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php
index 11af21491..04cda7312 100644
--- a/system/libraries/User_agent.php
+++ b/system/libraries/User_agent.php
@@ -84,7 +84,7 @@ class CI_User_agent {
*/
private function _load_agent_file()
{
- if (is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT))
+ if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT))
{
include(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT);
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 013c55766..26e9bbc3b 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -68,6 +68,7 @@ Hg Tag: n/a</p>
<ul>
<li class="reactor"><kbd>constants.php</kbd> will now be loaded from the environment folder if available.</li>
<li class="reactor">Added language key error logging</li>
+ <li class="reactor">Made Environment Support optional. Comment out or delete the constant to stop environment checks.</li>
<li class="reactor">Added Environment Support for Hooks.</li>
<li class="reactor">Added CI_ Prefix to the <a href="libraries/caching.html">Cache driver</a>.</li>
</ul>
diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html
index dc06c87be..64596e271 100644
--- a/user_guide/database/active_record.html
+++ b/user_guide/database/active_record.html
@@ -545,6 +545,30 @@ $this->db->insert_batch('mytable', $data);
<p>The first parameter will contain the table name, the second is an associative array of values.</p>
+<h2>$this->db->insert_batch();</h2>
+<p>Generates an insert string based on the data you supply, and runs the query. You can either pass an
+<strong>array</strong> or an <strong>object</strong> to the function. Here is an example using an array:</p>
+
+<code>
+$data = array(<br/>
+&nbsp;&nbsp;&nbsp;array(<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'title' => 'My title' ,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name' => 'My Name' ,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'date' => 'My date'<br />
+&nbsp;&nbsp;&nbsp;),<br />
+&nbsp;&nbsp;&nbsp;array(<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'title' => 'Another title' ,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name' => 'Another Name' ,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'date' => 'Another date'<br />
+&nbsp;&nbsp;&nbsp;)<br/>
+);<br />
+<br />
+$this->db->update_batch('mytable', $data);
+<br /><br />
+// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')</code>
+
+<p>The first parameter will contain the table name, the second is an associative array of values.</p>
+
<p class="important"><strong>Note:</strong> All values are escaped automatically producing safer queries.</p>