Merge pull request #2999 from vlakoff/error-templates

Make the error templates path configurable
diff --git a/application/config/config.php b/application/config/config.php
index ae89715..ba6867f 100644
--- a/application/config/config.php
+++ b/application/config/config.php
@@ -223,7 +223,7 @@
 |--------------------------------------------------------------------------
 |
 | Leave this BLANK unless you would like to set something other than the default
-| application/logs/ folder. Use a full server path with trailing slash.
+| application/logs/ directory. Use a full server path with trailing slash.
 |
 */
 $config['log_path'] = '';
@@ -255,11 +255,22 @@
 
 /*
 |--------------------------------------------------------------------------
+| Error Views Directory Path
+|--------------------------------------------------------------------------
+|
+| Leave this BLANK unless you would like to set something other than the default
+| application/views/errors/ directory.  Use a full server path with trailing slash.
+|
+*/
+$config['error_views_path'] = '';
+
+/*
+|--------------------------------------------------------------------------
 | Cache Directory Path
 |--------------------------------------------------------------------------
 |
 | Leave this BLANK unless you would like to set something other than the default
-| application/cache/ folder.  Use a full server path with trailing slash.
+| application/cache/ directory.  Use a full server path with trailing slash.
 |
 */
 $config['cache_path'] = '';
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 0418696..5bcb7c1 100644
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -145,6 +145,10 @@
 	 */
 	public function show_error($heading, $message, $template = 'error_general', $status_code = 500)
 	{
+		$templates_path = config_item('error_views_path')
+			? config_item('error_views_path')
+			: VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
+
 		if (is_cli())
 		{
 			$message = "\t".(is_array($message) ? implode("\n\t", $message) : $message);
@@ -162,7 +166,7 @@
 			ob_end_flush();
 		}
 		ob_start();
-		include(VIEWPATH.'errors'.DIRECTORY_SEPARATOR.$template.'.php');
+		include($templates_path.$template.'.php');
 		$buffer = ob_get_contents();
 		ob_end_clean();
 		return $buffer;
@@ -181,6 +185,10 @@
 	 */
 	public function show_php_error($severity, $message, $filepath, $line)
 	{
+		$templates_path = config_item('error_views_path')
+			? config_item('error_views_path')
+			: VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
+
 		$severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity;
 
 		// For safety reasons we don't show the full file path in non-CLI requests
@@ -205,7 +213,7 @@
 			ob_end_flush();
 		}
 		ob_start();
-		include(VIEWPATH.'errors'.DIRECTORY_SEPARATOR.$template.'.php');
+		include($templates_path.$template.'.php');
 		$buffer = ob_get_contents();
 		ob_end_clean();
 		echo $buffer;
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 9d3ceb0..a466977 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -48,6 +48,8 @@
    -  Removed previously deprecated EXT constant.
    -  Updated all classes to be written in PHP 5 style, with visibility declarations and no ``var`` usage for properties.
    -  Moved error templates to *application/views/errors/*.
+   -  Added support non-HTML error templates for CLI applications.
+   -  Made error templates path configurable using ``$config['error_views_path']``.
    -  Moved the Log class to *application/core/*
    -  Global config files are loaded first, then environment ones. Environment config keys overwrite base ones, allowing to only set the keys we want changed per environment.
    -  Changed detection of ``$view_folder`` so that if it's not found in the current path, it will now also be searched for under the application folder.
@@ -56,7 +58,6 @@
    -  Changed environment defaults to report all errors in *development* and only fatal ones in *testing*, *production* but only display them in *development*.
    -  Updated *ip_address* database field lengths from 16 to 45 for supporting IPv6 address on :doc:`Trackback Library <libraries/trackback>` and :doc:`Captcha Helper <helpers/captcha_helper>`.
    -  Removed *cheatsheets* and *quick_reference* PDFs from the documentation.
-   -  Added support non-HTML error templates for CLI applications.
    -  Added availability checks where usage of dangerous functions like ``eval()`` and ``exec()`` is required.
    -  Added support for changing the file extension of log files using ``$config['log_file_extension']``.
    -  Added support for turning newline standardization on/off via ``$config['standardize_newlines']``.
diff --git a/user_guide_src/source/general/managing_apps.rst b/user_guide_src/source/general/managing_apps.rst
index 3ca0e03..4861ba7 100644
--- a/user_guide_src/source/general/managing_apps.rst
+++ b/user_guide_src/source/general/managing_apps.rst
@@ -40,14 +40,12 @@
 	applications/foo/
 	applications/foo/config/
 	applications/foo/controllers/
-	applications/foo/errors/
 	applications/foo/libraries/
 	applications/foo/models/
 	applications/foo/views/
 	applications/bar/
 	applications/bar/config/
 	applications/bar/controllers/
-	applications/bar/errors/
 	applications/bar/libraries/
 	applications/bar/models/
 	applications/bar/views/
diff --git a/user_guide_src/source/helpers/smiley_helper.rst b/user_guide_src/source/helpers/smiley_helper.rst
index b980840..e7a5724 100644
--- a/user_guide_src/source/helpers/smiley_helper.rst
+++ b/user_guide_src/source/helpers/smiley_helper.rst
@@ -75,7 +75,7 @@
 
 	}
 
-In your **application/views/** folder, create a file called **smiley_view.php**
+In your **application/views/** directory, create a file called **smiley_view.php**
 and place this code in it::
 
 	<html>