Commits

Phil Sturgeon committed c79040f

Made Environment Support optional. Comment out or delete the constant to stop environment checks.

Comments (0)

Files changed (18)

  * By default development will show errors but testing and live will hide them.
  */
 
+if (defined('ENVIRONMENT'))
+{
 	switch (ENVIRONMENT)
 	{
 		case 'development':
 		default:
 			exit('The application environment is not set correctly.');
 	}
+}
 
 /*
  *---------------------------------------------------------------

system/core/CodeIgniter.php

  *  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);
 	}

system/core/Common.php

 			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?

system/core/Config.php

 	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;
+				$file_path = $path.'config/'.$location.EXT;
+
+				if (in_array($file_path, $this->is_loaded, TRUE))
+				{
+					$loaded = TRUE;
+					continue 2;
+				}
+
+				if (file_exists($file_path))
+				{
+					$found = TRUE;
+					break;
+				}
+			}
+
+			if ($found === FALSE)
+			{
 				continue;
 			}
 
-			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))
-				{
-					continue;
-				}
-			}
-			
 			include($file_path);
 
 			if ( ! isset($config) OR ! is_array($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;
 	}
 
 // END CI_Config class
 
 /* End of file Config.php */
-/* Location: ./system/core/Config.php */
+/* Location: ./system/core/Config.php */

system/core/Hooks.php

 		// 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);
 		}

system/core/Loader.php

 					// 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;
 	 */
 	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);
 		}

system/core/Output.php

 		$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;
 		}

system/core/Router.php

 		}
 
 		// 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);
 		}

system/database/DB.php

 	// 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.');
 			}
 		}
 		

system/helpers/download_helper.php

 		$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);
 		}

system/helpers/file_helper.php

 
 		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);
 			}

system/helpers/html_helper.php

 
 		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);
 			}

system/helpers/smiley_helper.php

 {
 	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;
 	}
 }
 

system/helpers/text_helper.php

 {
 	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);
 		}

system/libraries/Upload.php

 
 		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);
 			}

system/libraries/User_agent.php

 	 */
 	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);
 		}

user_guide/changelog.html

 		<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>

user_guide/database/active_record.html

 
 <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>