summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/codeigniter/CodeIgniter.php15
-rw-r--r--system/codeigniter/Common.php2
-rw-r--r--system/drivers/DB_active_record.php2
-rw-r--r--system/drivers/DB_driver.php2
-rw-r--r--system/helpers/date_helper.php2
-rw-r--r--system/helpers/text_helper.php2
-rw-r--r--system/libraries/Email.php4
-rw-r--r--system/libraries/Image_lib.php2
-rw-r--r--system/libraries/Log.php6
-rw-r--r--system/libraries/Output.php2
-rw-r--r--system/libraries/Pagination.php2
-rw-r--r--system/libraries/Router.php14
-rw-r--r--system/libraries/Session.php2
-rw-r--r--system/libraries/Trackback.php4
-rw-r--r--system/libraries/URI.php4
-rw-r--r--system/libraries/Validation.php8
-rw-r--r--user_guide/general/changelog.html2
-rw-r--r--user_guide/general/controllers.html36
18 files changed, 81 insertions, 30 deletions
diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php
index 1f7850ecf..5c3d19b76 100644
--- a/system/codeigniter/CodeIgniter.php
+++ b/system/codeigniter/CodeIgniter.php
@@ -192,13 +192,20 @@ else
{
$method = 'index';
}
-
- if ( ! method_exists($CI, $method))
+
+ if (method_exists($CI, '_remap'))
{
- show_404();
+ $CI->_remap($method);
}
+ else
+ {
+ if ( ! method_exists($CI, $method))
+ {
+ show_404();
+ }
- $CI->$method();
+ $CI->$method();
+ }
}
/*
diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php
index d5bec77fe..1b190e201 100644
--- a/system/codeigniter/Common.php
+++ b/system/codeigniter/Common.php
@@ -175,7 +175,7 @@ function log_message($level = 'error', $message, $php_error = FALSE)
$config['log_threshold'],
$config['log_date_format']
);
- }
+ }
$LOG->write_log($level, $message, $php_error);
}
diff --git a/system/drivers/DB_active_record.php b/system/drivers/DB_active_record.php
index f1995c807..1320af9ed 100644
--- a/system/drivers/DB_active_record.php
+++ b/system/drivers/DB_active_record.php
@@ -790,7 +790,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
- if (ctype_digit($this->ar_limit))
+ if (is_numeric($this->ar_limit))
{
$sql .= "\n";
$sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
diff --git a/system/drivers/DB_driver.php b/system/drivers/DB_driver.php
index 0c2084ad8..5fcb04a00 100644
--- a/system/drivers/DB_driver.php
+++ b/system/drivers/DB_driver.php
@@ -352,7 +352,7 @@ class CI_DB_driver {
*/
function escape($str)
{
- if ( ! ctype_digit($str)) // bug fix to ensure that numbers are not treated as strings.
+ if ( ! is_numeric($str)) // bug fix to ensure that numbers are not treated as strings.
{
switch (gettype($str))
{
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index c8205bb7d..ab3a31867 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -223,7 +223,7 @@ function days_in_month($month = 0, $year = '')
return 0;
}
- if ( ! ctype_digit($year) OR strlen($year) != 4)
+ if ( ! is_numeric($year) OR strlen($year) != 4)
{
$year = date('Y');
}
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 15b5573bf..e4f816eb1 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -333,7 +333,7 @@ function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '<
*/
function word_wrap($str, $chars = '76')
{
- if ( ! ctype_digit($chars))
+ if ( ! is_numeric($chars))
$chars = 76;
$str = preg_replace("/(\r\n|\r|\n)/", "\n", $str);
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index 96dc0014d..abc77a54d 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -275,7 +275,7 @@ class CI_Email {
*/
function bcc($bcc, $limit = '')
{
- if ($limit != '' && ctype_digit($limit))
+ if ($limit != '' && is_numeric($limit))
{
$this->bcc_batch_mode = true;
$this->bcc_batch_size = $limit;
@@ -475,7 +475,7 @@ class CI_Email {
*/
function set_priority($n = 3)
{
- if ( ! ctype_digit($n))
+ if ( ! is_numeric($n))
{
$this->priority = 3;
return;
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index 854f0484b..18e3253f7 100644
--- a/system/libraries/Image_lib.php
+++ b/system/libraries/Image_lib.php
@@ -291,7 +291,7 @@ class CI_Image_lib {
// Set the quality
$this->quality = trim(str_replace("%", "", $this->quality));
- if ($this->quality == '' OR $this->quality == 0 OR ! ctype_digit($this->quality))
+ if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality))
$this->quality = 90;
// Set the x/y coordinates
diff --git a/system/libraries/Log.php b/system/libraries/Log.php
index de5a9b836..6c78316f1 100644
--- a/system/libraries/Log.php
+++ b/system/libraries/Log.php
@@ -43,13 +43,13 @@ class CI_Log {
function CI_Log($path = '', $threshold = 4, $date_fmt = '')
{
$this->log_path = ($path != '') ? $path : BASEPATH.'logs/';
-
+
if ( ! is_dir($this->log_path) OR ! is_writable($this->log_path))
{
$this->_enabled = FALSE;
}
- if (ctype_digit($threshold))
+ if (is_numeric($threshold))
{
$this->_threshold = $threshold;
}
@@ -77,7 +77,7 @@ class CI_Log {
function write_log($level = 'error', $msg, $php_error = FALSE)
{
if ($this->_enabled === FALSE)
- {
+ {
return FALSE;
}
diff --git a/system/libraries/Output.php b/system/libraries/Output.php
index 73f03863e..7a03cf9c7 100644
--- a/system/libraries/Output.php
+++ b/system/libraries/Output.php
@@ -78,7 +78,7 @@ class CI_Output {
*/
function cache($time)
{
- $this->cache_expiration = ( ! ctype_digit($time)) ? 0 : $time;
+ $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time;
}
// --------------------------------------------------------------------
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index 0bbb577a3..9d558f00a 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -128,7 +128,7 @@ class CI_Pagination {
$this->cur_page = $obj->uri->segment($this->uri_segment);
}
- if ( ! ctype_digit($this->cur_page))
+ if ( ! is_numeric($this->cur_page))
{
$this->cur_page = 0;
}
diff --git a/system/libraries/Router.php b/system/libraries/Router.php
index 2219f5739..1c67113f6 100644
--- a/system/libraries/Router.php
+++ b/system/libraries/Router.php
@@ -219,15 +219,23 @@ class CI_Router {
{
return $segments;
}
-
+
// Is the controller in a sub-folder?
if (is_dir(APPPATH.'controllers/'.$segments['0']))
- {
+ {
// Set the directory and remove it from the segment array
$this->set_directory($segments['0']);
$segments = array_slice($segments, 1);
- if (count($segments) == 0)
+ if (count($segments) > 0)
+ {
+ // Does the requested controller exist in the sub-folder?
+ if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments['0'].EXT))
+ {
+ show_404();
+ }
+ }
+ else
{
$this->set_class($this->default_controller);
$this->set_method('index');
diff --git a/system/libraries/Session.php b/system/libraries/Session.php
index 4f08cf692..94efee55c 100644
--- a/system/libraries/Session.php
+++ b/system/libraries/Session.php
@@ -99,7 +99,7 @@ class CI_Session {
*/
$expiration = $this->object->config->item('sess_expiration');
- if (ctype_digit($expiration))
+ if (is_numeric($expiration))
{
if ($expiration > 0)
{
diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php
index 583c6d28d..8f9680d44 100644
--- a/system/libraries/Trackback.php
+++ b/system/libraries/Trackback.php
@@ -368,7 +368,7 @@ class CI_Trackback {
$tb_array = explode('/', $url);
$tb_end = $tb_array[count($tb_array)-1];
- if ( ! ctype_digit($tb_end))
+ if ( ! is_numeric($tb_end))
{
$tb_end = $tb_array[count($tb_array)-2];
}
@@ -386,7 +386,7 @@ class CI_Trackback {
$tb_array = explode('/', $url);
$tb_id = $tb_array[count($tb_array)-1];
- if ( ! ctype_digit($tb_id))
+ if ( ! is_numeric($tb_id))
{
$tb_id = $tb_array[count($tb_array)-2];
}
diff --git a/system/libraries/URI.php b/system/libraries/URI.php
index c5fd4625b..ba6279e88 100644
--- a/system/libraries/URI.php
+++ b/system/libraries/URI.php
@@ -88,7 +88,7 @@ class CI_URI {
*/
function uri_to_assoc($n = 3, $default = array())
{
- if ( ! ctype_digit($n))
+ if ( ! is_numeric($n))
{
return $default;
}
@@ -110,7 +110,7 @@ class CI_URI {
{
$retval[$val] = FALSE;
}
- return $default;
+ return $retval;
}
$segments = array_slice($this->segment_array(), ($n - 1));
diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php
index 30faa85ed..44f49ff62 100644
--- a/system/libraries/Validation.php
+++ b/system/libraries/Validation.php
@@ -404,7 +404,7 @@ class CI_Validation {
*/
function min_length($str, $val)
{
- if ( ! ctype_digit($val))
+ if ( ! is_numeric($val))
{
return FALSE;
}
@@ -423,7 +423,7 @@ class CI_Validation {
*/
function max_length($str, $val)
{
- if ( ! ctype_digit($val))
+ if ( ! is_numeric($val))
{
return FALSE;
}
@@ -442,7 +442,7 @@ class CI_Validation {
*/
function exact_length($str, $val)
{
- if ( ! ctype_digit($val))
+ if ( ! is_numeric($val))
{
return FALSE;
}
@@ -517,7 +517,7 @@ class CI_Validation {
*/
function numeric($str)
{
- return ( ! ctype_digit($str)) ? FALSE : TRUE;
+ return ( ! is_numeric($str)) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
diff --git a/user_guide/general/changelog.html b/user_guide/general/changelog.html
index 168e72fef..370cd0447 100644
--- a/user_guide/general/changelog.html
+++ b/user_guide/general/changelog.html
@@ -71,6 +71,7 @@ Change Log
<li>Added <a href="hooks.html">Hooks</a> feature, enabling you to tap into and modify the inner workings of the framework without hacking the core files.</li>
<li>Added the ability to organize controller files <a href="controllers.html">into sub-folders</a>. Kudos to Marco for <a href="http://www.codeigniter.com/forums/viewthread/627/">suggesting</a> this (and the next two) feature.</li>
<li>Added regular expressions support for <a href="routing.html">routing rules</a>.</li>
+<li>Added the ability to <a href="controllers.html">remap function calls</a> withing your controllers.</li>
<li>Added the ability to <a href="core_classes.html">replace core system classes</a> with your own classes.</li>
<li>Added support for % character in URL.</li>
<li>Added the ability to supply full URLs using the <a href="../helpers/url_helper.html">anchor()</a> helper function.</li>
@@ -107,6 +108,7 @@ Change Log
<li>Fixed a bug in the <dfn>set_hash()</dfn> function which was preventing MD5 from being used.</li>
<li>Fixed a couple bugs in the Unit Testing class.</li>
<li>Fixed an incorrectly named variable in the Validation class.</li>
+<li>Fixed an incorrectly named variable in the URI class.</li>
<li>Fixed some MS SQL bugs.</li>
<li>Fixed some doc typos.</li>
</ul>
diff --git a/user_guide/general/controllers.html b/user_guide/general/controllers.html
index 4dc94cba6..3ea0b61c4 100644
--- a/user_guide/general/controllers.html
+++ b/user_guide/general/controllers.html
@@ -69,6 +69,7 @@ Controllers
<li><a href="#what">What is a Controller?</a></li>
<li><a href="#hello">Hello World</a></li>
<li><a href="#functions">Functions</a></li>
+<li><a href="#remapping">Remapping Function Calls</a></li>
<li><a href="#private">Private Functions</a></li>
<li><a href="#default">Defining a Default Controller</a></li>
<li><a href="#subfolders">Organizing Controllers into Sub-folders</a></li>
@@ -174,10 +175,43 @@ class Blog extends Controller {
<p>You should see your new message.</p>
+
+<a name="remapping"></a>
+<h2>Remapping Function Calls</h2>
+
+<p>As noted above, the second segment of the URI typically determines which function in the controller gets called.
+Code Igniter permits you to override this behavior through the use of the <kbd>_remap()</kbd> function:</p>
+
+<code>function _remap()<br />
+{<br />
+&nbsp;&nbsp;&nbsp;&nbsp;// Some code here...<br />
+}</code>
+
+<p class="important"><strong>Important:</strong>&nbsp; If your controller contains a function named <kbd>_remap()</kbd>, it will <strong>always</strong>
+get called regardless of what your URI contains. It overrides the normal behavior in which the URI determines which function is called,
+allowing you to define your own function routing rules.</p>
+
+<p>The overriden function call (typically the second segment of the URI) will be passed as a parameter the <kbd>_remap()</kbd> function:</p>
+
+<code>function _remap(<var>$method</var>)<br />
+{<br />
+&nbsp;&nbsp;&nbsp;&nbsp;if ($method == 'some_method')<br />
+&nbsp;&nbsp;&nbsp;&nbsp;{<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->$method();<br />
+&nbsp;&nbsp;&nbsp;&nbsp;}<br />
+&nbsp;&nbsp;&nbsp;&nbsp;else<br />
+&nbsp;&nbsp;&nbsp;&nbsp;{<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->default_method();<br />
+&nbsp;&nbsp;&nbsp;&nbsp;}<br />
+}</code>
+
+
+
+
<a name="private"></a>
<h2>Private Functions</h2>
-<p>In some cases you may not want certain functions accessible publicly. To make a function private, simply add an
+<p>In some cases you may want certain functions hidden from public access. To make a function private, simply add an
underscore as the name prefix and it will not be served via a URL request. For example, if you were to have a function like this:</p>
<code>