Commits

Anonymous committed 7a35509

Comments (0)

Files changed (18)

system/codeigniter/CodeIgniter.php

 	{
 		$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();
+	}
 }
 
 /*

system/codeigniter/Common.php

 							$config['log_threshold'], 
 							$config['log_date_format']
 						);
-	}
+	}	
 	
 	$LOG->write_log($level, $message, $php_error);
 }

system/drivers/DB_active_record.php

 			}		
 		}
 		
-		if (ctype_digit($this->ar_limit))
+		if (is_numeric($this->ar_limit))
 		{
 			$sql .= "\n";
 			$sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);

system/drivers/DB_driver.php

 	 */	
 	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))
 			{

system/helpers/date_helper.php

 		return 0;
 	}
 	
-	if ( ! ctype_digit($year) OR strlen($year) != 4)
+	if ( ! is_numeric($year) OR strlen($year) != 4)
 	{
 		$year = date('Y');
 	}

system/helpers/text_helper.php

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

system/libraries/Email.php

 	 */	
 	function bcc($bcc, $limit = '')
 	{
-		if ($limit != '' && ctype_digit($limit))
+		if ($limit != '' && is_numeric($limit))
 		{
 			$this->bcc_batch_mode = true;
 			$this->bcc_batch_size = $limit;
 	 */	
 	function set_priority($n = 3)
 	{
-		if ( ! ctype_digit($n))
+		if ( ! is_numeric($n))
 		{
 			$this->priority = 3;
 			return;

system/libraries/Image_lib.php

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

system/libraries/Log.php

 	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;
 		}
 	function write_log($level = 'error', $msg, $php_error = FALSE)
 	{		
 		if ($this->_enabled === FALSE)
-		{
+		{ 
 			return FALSE;
 		}
 	

system/libraries/Output.php

 	 */	
 	function cache($time)
 	{
-		$this->cache_expiration = ( ! ctype_digit($time)) ? 0 : $time;
+		$this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time;
 	}
 	
 	// --------------------------------------------------------------------

system/libraries/Pagination.php

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

system/libraries/Router.php

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

system/libraries/Session.php

 		 */
 		$expiration = $this->object->config->item('sess_expiration');
 		
-		if (ctype_digit($expiration))
+		if (is_numeric($expiration))
 		{
 			if ($expiration > 0)
 			{

system/libraries/Trackback.php

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

system/libraries/URI.php

 	 */
 	function uri_to_assoc($n = 3, $default = array())
 	{
-		if ( ! ctype_digit($n))
+		if ( ! is_numeric($n))
 		{
 			return $default;
 		}
 			{
 				$retval[$val] = FALSE;
 			}		
-			return $default;
+			return $retval;
 		}
 
 		$segments = array_slice($this->segment_array(), ($n - 1));

system/libraries/Validation.php

 	 */	
 	function min_length($str, $val)
 	{
-		if ( ! ctype_digit($val))
+		if ( ! is_numeric($val))
 		{
 			return FALSE;
 		}
 	 */	
 	function max_length($str, $val)
 	{
-		if ( ! ctype_digit($val))
+		if ( ! is_numeric($val))
 		{
 			return FALSE;
 		}
 	 */	
 	function exact_length($str, $val)
 	{
-		if ( ! ctype_digit($val))
+		if ( ! is_numeric($val))
 		{
 			return FALSE;
 		}
 	 */	
 	function numeric($str)
 	{
-		return ( ! ctype_digit($str)) ? FALSE : TRUE;
+		return ( ! is_numeric($str)) ? FALSE : TRUE;
 	}
 	
 	// --------------------------------------------------------------------

user_guide/general/changelog.html

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

user_guide/general/controllers.html

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