Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Unconstantised Paths #649

Closed
wants to merge 2 commits into from

3 participants

@jamierumbelow

I was writing an EE add-on earlier and I needed to adjust the loading paths of some of the internal libraries. While you can alter the paths for libraries, models, helpers and views in the Loader, there are some bits of code where the paths are hard-coded with the BASEPATH and APPPATH constants.

In this commit, I've changed (most) of the internal references to BASEPATH, APPPATH and VIEWPATH to use the newly added system_path() function. The system_path() registry means that we can swap out the paths for things such as the database connection with minimal problems. It also just gives the system another tier of flexibility.

I've left the constants in place for the time being for backward compatibility, and I've also added documentation to this commit so that eventually we could phase out the constants entirely.

jamierumbelow added some commits
@jamierumbelow jamierumbelow Overhauling the way that paths are referenced internally
CodeIgniter now uses the system_path() function rather than the various constants. This allows developers much greater flexibility when altering load paths in the underlying code.
0782ced
@jamierumbelow jamierumbelow Adding some documentation for the system_path() function 6e9f1e4
@cryode

This is an interesting submission - I'm surprised no one ever commented on it, regardless of its age.

I've never had a need to change these paths. Can @jamierumbelow or someone give a potential use case where this is beneficial? When would I use this function to change a path's value?

Other randoms:

  • Maybe the function's placement would be better in either /system/core/Common.php or index.php?
  • A different name for the function, maybe ci_path(). system_path() immediately makes me think of the system folder specifically.
  • Ditch the "path" suffix for the parameter, and stick with things like app, system or maybe core, views, etc.
@narfbg narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 5, 2011
  1. @jamierumbelow

    Overhauling the way that paths are referenced internally

    jamierumbelow authored
    CodeIgniter now uses the system_path() function rather than the various constants. This allows developers much greater flexibility when altering load paths in the underlying code.
  2. @jamierumbelow
This page is out of date. Refresh to see the latest.
View
2  application/config/autoload.php
@@ -59,7 +59,7 @@
| -------------------------------------------------------------------
| Prototype:
|
-| $autoload['packages'] = array(APPPATH.'third_party', '/usr/local/shared');
+| $autoload['packages'] = array(system_path('apppath').'third_party', '/usr/local/shared');
|
*/
View
2  application/config/migration.php
@@ -90,7 +90,7 @@
| Also, writing permission is required within the migrations path.
|
*/
-$config['migration_path'] = APPPATH . 'migrations/';
+$config['migration_path'] = system_path('apppath') . 'migrations/';
/* End of file migration.php */
View
20 system/core/CodeIgniter.php
@@ -59,7 +59,7 @@
* Load the framework constants
* ------------------------------------------------------
*/
- if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
+ if (defined('ENVIRONMENT') AND file_exists(system_path('apppath').'config/'.ENVIRONMENT.'/constants.php'))
{
require(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
}
@@ -230,7 +230,7 @@
*
*/
// Load the base controller class
- require BASEPATH.'core/Controller.php';
+ require system_path('basepath').'core/Controller.php';
function &get_instance()
{
@@ -238,20 +238,20 @@ function &get_instance()
}
- if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
+ if (file_exists(system_path('apppath').'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
{
- require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
+ require system_path('apppath').'core/'.$CFG->config['subclass_prefix'].'Controller.php';
}
// Load the local application controller
// Note: The Router class automatically validates the controller path using the router->_validate_request().
// If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
- if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'))
+ if ( ! file_exists(system_path('apppath').'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'))
{
show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
}
- include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php');
+ include(system_path('apppath').'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php');
// Set a mark point for benchmarking
$BM->mark('loading_time:_base_classes_end');
@@ -280,12 +280,12 @@ function &get_instance()
$method = (isset($x[1]) ? $x[1] : 'index');
if ( ! class_exists($class))
{
- if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
+ if ( ! file_exists(system_path('apppath').'controllers/'.$class.'.php'))
{
show_404("{$class}/{$method}");
}
- include_once(APPPATH.'controllers/'.$class.'.php');
+ include_once(system_path('apppath').'controllers/'.$class.'.php');
}
}
else
@@ -342,12 +342,12 @@ function &get_instance()
$method = (isset($x[1]) ? $x[1] : 'index');
if ( ! class_exists($class))
{
- if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
+ if ( ! file_exists(system_path('apppath').'controllers/'.$class.'.php'))
{
show_404("{$class}/{$method}");
}
- include_once(APPPATH.'controllers/'.$class.'.php');
+ include_once(system_path('apppath').'controllers/'.$class.'.php');
unset($CI);
$CI = new $class();
}
View
47 system/core/Common.php
@@ -146,7 +146,7 @@ function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
// Look for the class first in the local application/libraries folder
// then in the native system/libraries folder
- foreach (array(APPPATH, BASEPATH) as $path)
+ foreach (array(system_path('apppath'), system_path('basepath')) as $path)
{
if (file_exists($path.$directory.'/'.$class.'.php'))
{
@@ -162,13 +162,13 @@ function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
}
// Is the request a class extension? If so we load it too
- if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'))
+ if (file_exists(system_path('apppath').$directory.'/'.config_item('subclass_prefix').$class.'.php'))
{
$name = config_item('subclass_prefix').$class;
if (class_exists($name) === FALSE)
{
- require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php');
+ require(system_path('apppath').$directory.'/'.config_item('subclass_prefix').$class.'.php');
}
}
@@ -212,6 +212,43 @@ function is_loaded($class = '')
}
}
+// --------------------------------------------------------------------
+
+/**
+* Keeps track of the various paths to system directories. Enables developers
+* to swap out paths to the application and view directories at runtime.
+*
+* @access public
+* @return mixed
+*/
+if ( ! function_exists('system_path'))
+{
+ function system_path($path = '', $new_path = '')
+ {
+ static $_system_paths = array(
+ 'basepath' => BASEPATH,
+ 'apppath' => APPPATH,
+ 'viewpath' => VIEWPATH
+ );
+
+ if ($path == '')
+ {
+ return $_system_paths;
+ }
+ else
+ {
+ if ($new_path == '')
+ {
+ return (isset($_system_paths[$path])) ? $_system_paths[$path] : $_system_paths;
+ }
+ else
+ {
+ $_system_paths[$path] = $new_path;
+ }
+ }
+ }
+}
+
// ------------------------------------------------------------------------
/**
@@ -235,9 +272,9 @@ function &get_config($replace = array())
}
// Is the config file in the environment folder?
- if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
+ if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = system_path('apppath').'config/'.ENVIRONMENT.'/config.php'))
{
- $file_path = APPPATH.'config/config.php';
+ $file_path = system_path('apppath').'config/config.php';
}
// Fetch the config file
View
5 system/core/Config.php
@@ -57,7 +57,7 @@ class CI_Config {
*
* @var array
*/
- var $_config_paths = array(APPPATH);
+ var $_config_paths = array();
/**
* Constructor
@@ -72,6 +72,7 @@ class CI_Config {
*/
function __construct()
{
+ $this->_config_paths = array(system_path('apppath'));
$this->config =& get_config();
log_message('debug', "Config Class Initialized");
@@ -341,7 +342,7 @@ protected function _uri_string($uri)
*/
function system_url()
{
- $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
+ $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", system_path('basepath')));
return $this->slash_item('base_url').end($x).'/';
}
View
4 system/core/Exceptions.php
@@ -155,7 +155,7 @@ function show_error($heading, $message, $template = 'error_general', $status_cod
ob_end_flush();
}
ob_start();
- include(APPPATH.'errors/'.$template.'.php');
+ include(system_path('apppath').'errors/'.$template.'.php');
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
@@ -191,7 +191,7 @@ function show_php_error($severity, $message, $filepath, $line)
ob_end_flush();
}
ob_start();
- include(APPPATH.'errors/error_php.php');
+ include(system_path('apppath').'errors/error_php.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
View
10 system/core/Hooks.php
@@ -92,13 +92,13 @@ function _initialize()
// Grab the "hooks" definition file.
// If there are no hooks, we're done.
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'))
+ if (defined('ENVIRONMENT') AND is_file(system_path('apppath').'config/'.ENVIRONMENT.'/hooks.php'))
{
- include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php');
+ include(system_path('apppath').'config/'.ENVIRONMENT.'/hooks.php');
}
- elseif (is_file(APPPATH.'config/hooks.php'))
+ elseif (is_file(system_path('apppath').'config/hooks.php'))
{
- include(APPPATH.'config/hooks.php');
+ include(system_path('apppath').'config/hooks.php');
}
@@ -183,7 +183,7 @@ function _run_hook($data)
return FALSE;
}
- $filepath = APPPATH.$data['filepath'].'/'.$data['filename'];
+ $filepath = system_path('apppath').$data['filepath'].'/'.$data['filename'];
if ( ! file_exists($filepath))
{
View
44 system/core/Loader.php
@@ -136,10 +136,10 @@ class CI_Loader {
public function __construct()
{
$this->_ci_ob_level = ob_get_level();
- $this->_ci_library_paths = array(APPPATH, BASEPATH);
- $this->_ci_helper_paths = array(APPPATH, BASEPATH);
- $this->_ci_model_paths = array(APPPATH);
- $this->_ci_view_paths = array(VIEWPATH => TRUE);
+ $this->_ci_library_paths = array(system_path('apppath'), system_path('basepath'));
+ $this->_ci_helper_paths = array(system_path('apppath'), system_path('basepath'));
+ $this->_ci_model_paths = array(system_path('apppath'));
+ $this->_ci_view_paths = array(system_path('viewpath') => TRUE);
log_message('debug', "Loader Class Initialized");
}
@@ -343,7 +343,7 @@ public function database($params = '', $return = FALSE, $active_record = NULL)
return FALSE;
}
- require_once(BASEPATH.'database/DB.php');
+ require_once(system_path('basepath').'database/DB.php');
if ($return === TRUE)
{
@@ -378,8 +378,8 @@ public function dbutil()
// this use is deprecated and strongly discouraged
$CI->load->dbforge();
- require_once(BASEPATH.'database/DB_utility.php');
- require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php');
+ require_once(system_path('basepath').'database/DB_utility.php');
+ require_once(system_path('basepath').'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php');
$class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
$CI->dbutil = new $class();
@@ -401,8 +401,8 @@ public function dbforge()
$CI =& get_instance();
- require_once(BASEPATH.'database/DB_forge.php');
- require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php');
+ require_once(system_path('basepath').'database/DB_forge.php');
+ require_once(system_path('basepath').'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php');
$class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
$CI->dbforge = new $class();
@@ -511,12 +511,12 @@ public function helper($helpers = array())
continue;
}
- $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.'.php';
+ $ext_helper = system_path('apppath').'helpers/'.config_item('subclass_prefix').$helper.'.php';
// Is this a helper extension request?
if (file_exists($ext_helper))
{
- $base_helper = BASEPATH.'helpers/'.$helper.'.php';
+ $base_helper = system_path('basepath').'helpers/'.$helper.'.php';
if ( ! file_exists($base_helper))
{
@@ -625,7 +625,7 @@ public function driver($library = '', $params = NULL, $object_name = NULL)
if ( ! class_exists('CI_Driver_Library'))
{
// we aren't instantiating an object here, that'll be done by the Library itself
- require BASEPATH.'libraries/Driver.php';
+ require system_path('basepath').'libraries/Driver.php';
}
if ($library == '')
@@ -731,11 +731,11 @@ public function remove_package_path($path = '', $remove_config_path = TRUE)
}
// make sure the application default paths are still in the array
- $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH)));
- $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH)));
- $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH)));
- $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE));
- $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH)));
+ $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(system_path('apppath'), system_path('basepath'))));
+ $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(system_path('apppath'), system_path('basepath'))));
+ $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(system_path('apppath'))));
+ $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(system_path('viewpath') => TRUE));
+ $config->_config_paths = array_unique(array_merge($config->_config_paths, array(system_path('apppath'))));
}
// --------------------------------------------------------------------
@@ -910,12 +910,12 @@ protected function _ci_load_class($class, $params = NULL, $object_name = NULL)
// We'll test for both lowercase and capitalized versions of the file name
foreach (array(ucfirst($class), strtolower($class)) as $class)
{
- $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php';
+ $subclass = system_path('apppath').'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php';
// Is this a class extension request?
if (file_exists($subclass))
{
- $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php';
+ $baseclass = system_path('basepath').'libraries/'.ucfirst($class).'.php';
if ( ! file_exists($baseclass))
{
@@ -1125,13 +1125,13 @@ protected function _ci_init_class($class, $prefix = '', $config = FALSE, $object
*/
protected function _ci_autoloader()
{
- if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'))
+ if (defined('ENVIRONMENT') AND file_exists(system_path('apppath').'config/'.ENVIRONMENT.'/autoload.php'))
{
- include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php');
+ include(system_path('apppath').'config/'.ENVIRONMENT.'/autoload.php');
}
else
{
- include(APPPATH.'config/autoload.php');
+ include(system_path('apppath').'config/autoload.php');
}
if ( ! isset($autoload))
View
10 system/core/Output.php
@@ -106,13 +106,13 @@ function __construct()
$this->_zlib_oc = @ini_get('zlib.output_compression');
// Get mime types for later
- if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
+ if (defined('ENVIRONMENT') AND file_exists(system_path('apppath').'config/'.ENVIRONMENT.'/mimes.php'))
{
- include APPPATH.'config/'.ENVIRONMENT.'/mimes.php';
+ include system_path('apppath').'config/'.ENVIRONMENT.'/mimes.php';
}
else
{
- include APPPATH.'config/mimes.php';
+ include system_path('apppath').'config/mimes.php';
}
@@ -475,7 +475,7 @@ function _write_cache($output)
$CI =& get_instance();
$path = $CI->config->item('cache_path');
- $cache_path = ($path == '') ? APPPATH.'cache/' : $path;
+ $cache_path = ($path == '') ? system_path('apppath').'cache/' : $path;
if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
{
@@ -525,7 +525,7 @@ function _write_cache($output)
*/
function _display_cache(&$CFG, &$URI)
{
- $cache_path = ($CFG->item('cache_path') == '') ? APPPATH.'cache/' : $CFG->item('cache_path');
+ $cache_path = ($CFG->item('cache_path') == '') ? system_path('apppath').'cache/' : $CFG->item('cache_path');
// Build the file path. The file name is an MD5 hash of the full URI
$uri = $CFG->item('base_url').
View
16 system/core/Router.php
@@ -141,13 +141,13 @@ function _set_routing()
}
// Load the routes.php file.
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
+ if (defined('ENVIRONMENT') AND is_file(system_path('apppath').'config/'.ENVIRONMENT.'/routes.php'))
{
- include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
+ include(system_path('apppath').'config/'.ENVIRONMENT.'/routes.php');
}
- elseif (is_file(APPPATH.'config/routes.php'))
+ elseif (is_file(system_path('apppath').'config/routes.php'))
{
- include(APPPATH.'config/routes.php');
+ include(system_path('apppath').'config/routes.php');
}
$this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
@@ -281,13 +281,13 @@ function _validate_request($segments)
}
// Does the requested controller exist in the root folder?
- if (file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
+ if (file_exists(system_path('apppath').'controllers/'.$segments[0].'.php'))
{
return $segments;
}
// Is the controller in a sub-folder?
- if (is_dir(APPPATH.'controllers/'.$segments[0]))
+ if (is_dir(system_path('apppath').'controllers/'.$segments[0]))
{
// Set the directory and remove it from the segment array
$this->set_directory($segments[0]);
@@ -296,7 +296,7 @@ function _validate_request($segments)
if (count($segments) > 0)
{
// Does the requested controller exist in the sub-folder?
- if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
+ if ( ! file_exists(system_path('apppath').'controllers/'.$this->fetch_directory().$segments[0].'.php'))
{
if ( ! empty($this->routes['404_override']))
{
@@ -331,7 +331,7 @@ function _validate_request($segments)
}
// Does the default controller exist in the sub-folder?
- if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php'))
+ if ( ! file_exists(system_path('apppath').'controllers/'.$this->fetch_directory().$this->default_controller.'.php'))
{
$this->directory = '';
return array();
View
10 system/database/DB.php
@@ -42,9 +42,9 @@ function &DB($params = '', $active_record_override = NULL)
if (is_string($params) AND strpos($params, '://') === FALSE)
{
// Is the config file in the environment folder?
- if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
+ if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = system_path('apppath').'config/'.ENVIRONMENT.'/database.php'))
{
- if ( ! file_exists($file_path = APPPATH.'config/database.php'))
+ if ( ! file_exists($file_path = system_path('apppath').'config/database.php'))
{
show_error('The configuration file database.php does not exist.');
}
@@ -130,11 +130,11 @@ function &DB($params = '', $active_record_override = NULL)
$active_record = $active_record_override;
}
- require_once(BASEPATH.'database/DB_driver.php');
+ require_once(system_path('basepath').'database/DB_driver.php');
if ( ! isset($active_record) OR $active_record == TRUE)
{
- require_once(BASEPATH.'database/DB_active_rec.php');
+ require_once(system_path('basepath').'database/DB_active_rec.php');
if ( ! class_exists('CI_DB'))
{
@@ -149,7 +149,7 @@ function &DB($params = '', $active_record_override = NULL)
}
}
- require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php');
+ require_once(system_path('basepath').'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php');
// Instantiate the DB adapter
$driver = 'CI_DB_'.$params['dbdriver'].'_driver';
View
10 system/database/DB_driver.php
@@ -439,8 +439,8 @@ function load_rdriver()
if ( ! class_exists($driver))
{
- include_once(BASEPATH.'database/DB_result.php');
- include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php');
+ include_once(system_path('basepath').'database/DB_result.php');
+ include_once(system_path('basepath').'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php');
}
return $driver;
@@ -1131,7 +1131,7 @@ function _cache_init()
if ( ! class_exists('CI_DB_Cache'))
{
- if ( ! @include(BASEPATH.'database/DB_cache.php'))
+ if ( ! @include(system_path('basepath').'database/DB_cache.php'))
{
return $this->cache_off();
}
@@ -1193,10 +1193,10 @@ function display_error($error = '', $swap = '', $native = FALSE)
foreach ($trace as $call)
{
- if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE)
+ if (isset($call['file']) && strpos($call['file'], system_path('basepath').'database') === FALSE)
{
// Found it - use a relative path for safety
- $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']);
+ $message[] = 'Filename: '.str_replace(array(system_path('basepath'), system_path('apppath')), '', $call['file']);
$message[] = 'Line Number: '.$call['line'];
break;
View
8 system/helpers/download_helper.php
@@ -70,13 +70,13 @@ function force_download($filename = '', $data = '')
$extension = end($x);
// Load the mime types
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
+ if (defined('ENVIRONMENT') AND is_file(system_path('apppath').'config/'.ENVIRONMENT.'/mimes.php'))
{
- include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
+ include(system_path('apppath').'config/'.ENVIRONMENT.'/mimes.php');
}
- elseif (is_file(APPPATH.'config/mimes.php'))
+ elseif (is_file(system_path('apppath').'config/mimes.php'))
{
- include(APPPATH.'config/mimes.php');
+ include(system_path('apppath').'config/mimes.php');
}
// Set a default mime if we can't find it
View
8 system/helpers/file_helper.php
@@ -364,13 +364,13 @@ function get_mime_by_extension($file)
if ( ! is_array($mimes))
{
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
+ if (defined('ENVIRONMENT') AND is_file(system_path('apppath').'config/'.ENVIRONMENT.'/mimes.php'))
{
- include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
+ include(system_path('apppath').'config/'.ENVIRONMENT.'/mimes.php');
}
- elseif (is_file(APPPATH.'config/mimes.php'))
+ elseif (is_file(system_path('apppath').'config/mimes.php'))
{
- include(APPPATH.'config/mimes.php');
+ include(system_path('apppath').'config/mimes.php');
}
if ( ! is_array($mimes))
View
8 system/helpers/html_helper.php
@@ -275,13 +275,13 @@ function doctype($type = 'xhtml1-strict')
if ( ! is_array($_doctypes))
{
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'))
+ if (defined('ENVIRONMENT') AND is_file(system_path('apppath').'config/'.ENVIRONMENT.'/doctypes.php'))
{
- include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php');
+ include(system_path('apppath').'config/'.ENVIRONMENT.'/doctypes.php');
}
- elseif (is_file(APPPATH.'config/doctypes.php'))
+ elseif (is_file(system_path('apppath').'config/doctypes.php'))
{
- include(APPPATH.'config/doctypes.php');
+ include(system_path('apppath').'config/doctypes.php');
}
if ( ! is_array($_doctypes))
View
8 system/helpers/smiley_helper.php
@@ -241,13 +241,13 @@ function parse_smileys($str = '', $image_url = '', $smileys = NULL)
{
function _get_smiley_array()
{
- if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'))
+ if (defined('ENVIRONMENT') AND file_exists(system_path('apppath').'config/'.ENVIRONMENT.'/smileys.php'))
{
- include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php');
+ include(system_path('apppath').'config/'.ENVIRONMENT.'/smileys.php');
}
- elseif (file_exists(APPPATH.'config/smileys.php'))
+ elseif (file_exists(system_path('apppath').'config/smileys.php'))
{
- include(APPPATH.'config/smileys.php');
+ include(system_path('apppath').'config/smileys.php');
}
if (isset($smileys) AND is_array($smileys))
View
8 system/helpers/text_helper.php
@@ -378,13 +378,13 @@ function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '<
{
function convert_accented_characters($str)
{
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'))
+ if (defined('ENVIRONMENT') AND is_file(system_path('apppath').'config/'.ENVIRONMENT.'/foreign_chars.php'))
{
- include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php');
+ include(system_path('apppath').'config/'.ENVIRONMENT.'/foreign_chars.php');
}
- elseif (is_file(APPPATH.'config/foreign_chars.php'))
+ elseif (is_file(system_path('apppath').'config/foreign_chars.php'))
{
- include(APPPATH.'config/foreign_chars.php');
+ include(system_path('apppath').'config/foreign_chars.php');
}
if ( ! isset($foreign_characters))
View
2  system/libraries/Cache/drivers/Cache_file.php
@@ -51,7 +51,7 @@ public function __construct()
$path = $CI->config->item('cache_path');
- $this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path;
+ $this->_cache_path = ($path == '') ? system_path('apppath').'cache/' : $path;
}
// ------------------------------------------------------------------------
View
2  system/libraries/Encrypt.php
@@ -536,7 +536,7 @@ function sha1($str)
{
if ( ! function_exists('mhash'))
{
- require_once(BASEPATH.'libraries/Sha1.php');
+ require_once(system_path('basepath').'libraries/Sha1.php');
$SH = new CI_SHA;
return $SH->generate($str);
}
View
2  system/libraries/Log.php
@@ -53,7 +53,7 @@ public function __construct()
{
$config =& get_config();
- $this->_log_path = ($config['log_path'] != '') ? $config['log_path'] : APPPATH.'logs/';
+ $this->_log_path = ($config['log_path'] != '') ? $config['log_path'] : system_path('apppath').'logs/';
if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path))
{
View
2  system/libraries/Migration.php
@@ -71,7 +71,7 @@ public function __construct($config = array())
}
// If not set, set it
- $this->_migration_path == '' AND $this->_migration_path = APPPATH . 'migrations/';
+ $this->_migration_path == '' AND $this->_migration_path = system_path('apppath') . 'migrations/';
// Add trailing slash if not set
$this->_migration_path = rtrim($this->_migration_path, '/').'/';
View
8 system/libraries/Upload.php
@@ -960,13 +960,13 @@ public function mimes_types($mime)
if (count($this->mimes) == 0)
{
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
+ if (defined('ENVIRONMENT') AND is_file(system_path('apppath').'config/'.ENVIRONMENT.'/mimes.php'))
{
- include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
+ include(system_path('apppath').'config/'.ENVIRONMENT.'/mimes.php');
}
- elseif (is_file(APPPATH.'config/mimes.php'))
+ elseif (is_file(system_path('apppath').'config/mimes.php'))
{
- include(APPPATH.'config//mimes.php');
+ include(system_path('apppath').'config//mimes.php');
}
else
{
View
8 system/libraries/User_agent.php
@@ -96,13 +96,13 @@ public function __construct()
*/
private function _load_agent_file()
{
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'))
+ if (defined('ENVIRONMENT') AND is_file(system_path('apppath').'config/'.ENVIRONMENT.'/user_agents.php'))
{
- include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php');
+ include(system_path('apppath').'config/'.ENVIRONMENT.'/user_agents.php');
}
- elseif (is_file(APPPATH.'config/user_agents.php'))
+ elseif (is_file(system_path('apppath').'config/user_agents.php'))
{
- include(APPPATH.'config/user_agents.php');
+ include(system_path('apppath').'config/user_agents.php');
}
else
{
View
24 user_guide_src/source/general/common_functions.rst
@@ -51,6 +51,30 @@ accessing configuration information, however config_item() can be used
to retrieve single keys. See Config library documentation for more
information.
+system_path('path_name'), system_path('path_name', 'new_path')
+==============================================================
+
+Use system_path() to get a string of the path that you specify in the first
+parameter. These can be one of the following:
+
+- **basepath**, the path to the *system/* directory
+- **apppath**, the path to the *application/* directory
+- **viewpath**, the path to the *application/views/* directory
+
+Using this function instead of the older constants means that you can alter
+where the system is loading some of its core resources from at runtime. It
+also makes dynamically switching between application directories possible.
+
+You can not only use system_path() to retrieve the underlying paths, but
+change them too. Use the second parameter to specify a new path to change
+the path too.
+
+::
+
+ include system_path('apppath') . 'libraries/Secure_Controller.php';
+
+ system_path('viewpath', system_path('basepath') . '../views');
+
show_error('message'), show_404('page'), log_message('level', 'message')
========================================================================
View
1  user_guide_src/source/general/reserved_names.rst
@@ -28,6 +28,7 @@ Functions
- load_class()
- get_config()
- config_item()
+- system_path()
- show_error()
- show_404()
- log_message()
Something went wrong with that request. Please try again.