summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/core/Router.php10
-rw-r--r--user_guide_src/source/changelog.rst6
-rw-r--r--user_guide_src/source/general/routing.rst6
-rw-r--r--user_guide_src/source/general/urls.rst27
4 files changed, 39 insertions, 10 deletions
diff --git a/system/core/Router.php b/system/core/Router.php
index 87f3e9e63..89fb74f2f 100644
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -190,6 +190,7 @@ class CI_Router {
{
show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
}
+
// Is the method being specified?
if (strpos($this->default_controller, '/') !== FALSE)
{
@@ -268,9 +269,13 @@ class CI_Router {
return $segments;
}
+ $temp = str_replace('-', '_', $segments[0]);
+
// Does the requested controller exist in the root folder?
- if (file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
+ if (file_exists(APPPATH.'controllers/'.$temp.'.php'))
{
+ $segments[0] = $temp;
+ empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]);
return $segments;
}
@@ -283,6 +288,9 @@ class CI_Router {
if (count($segments) > 0)
{
+ $segments[0] = str_replace('-', '_', $segments[0]);
+ empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]);
+
// Does the requested controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
{
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 511ee00f6..8363d2797 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -46,7 +46,7 @@ Release Date: Not Released
Only entries in ``$autoload['libraries']`` are auto-loaded now.
- 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"
+ - Moved error templates to *application/views/errors*.
- 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.
- Path constants BASEPATH, APPPATH and VIEWPATH are now (internally) defined as absolute paths.
@@ -270,7 +270,9 @@ Release Date: Not Released
- Added method ``strip_image_tags()``.
- Added ``$config['csrf_regeneration']``, which makes token regeneration optional.
- Added ``$config['csrf_exclude_uris']``, which allows you list URIs which will not have the CSRF validation methods run.
- - Added possibility to route requests using callbacks.
+ - :doc:`URI Routing <general/routing>` changes include:
+ - Added possibility to route requests using callbacks.
+ - Added possibility to use dashes in the controller and method URI segments (translated to underscores).
Bug fixes for 3.0
------------------
diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst
index 43c181669..e6174cc0d 100644
--- a/user_guide_src/source/general/routing.rst
+++ b/user_guide_src/source/general/routing.rst
@@ -162,8 +162,8 @@ appear by default.
This route indicates which controller class should be loaded if the
requested controller is not found. It will override the default 404
error page. It won't affect to the show_404() function, which will
-continue loading the default error_404.php file at
-application/errors/error_404.php.
+continue loading the default *error_404.php* file at
+*application/errors/error_404.php*.
.. important:: The reserved routes must come before any wildcard or
- regular expression routes.
+ regular expression routes. \ No newline at end of file
diff --git a/user_guide_src/source/general/urls.rst b/user_guide_src/source/general/urls.rst
index 6b390b559..20f80632a 100644
--- a/user_guide_src/source/general/urls.rst
+++ b/user_guide_src/source/general/urls.rst
@@ -28,9 +28,28 @@ approach, usually represent::
#. The third, and any additional segments, represent the ID and any
variables that will be passed to the controller.
-The :doc:`URI Class <../libraries/uri>` and the :doc:`URL Helper <../helpers/url_helper>` contain functions that make it
-easy to work with your URI data. In addition, your URLs can be remapped
-using the :doc:`URI Routing <routing>` feature for more flexibility.
+The :doc:`URI Class <../libraries/uri>` and the :doc:`URL Helper <../helpers/url_helper>`
+contain functions that make it easy to work with your URI data. In addition,
+your URLs can be remapped using the :doc:`URI Routing <routing>` feature for
+more flexibility.
+
+Friendly URLs
+=============
+
+As you might guess, since there's a straight relationship between
+URI segments and the controller/method pair that's being called,
+those two determining segments must represent a valid class and
+method name.
+You may however also use dashes in the class/method-representing
+segments, and they will automatically be translated to underscores
+in order to be valid routed segments.
+
+For example::
+
+ example.com/my-settings/change-password/
+
+The above example will route to the ``My_settings`` controller and
+its method ``change_password()``.
Removing the index.php file
===========================
@@ -94,4 +113,4 @@ active. Your controllers and functions will then be accessible using the
.. note:: If you are using query strings you will have to build
your own URLs, rather than utilizing the URL helpers (and other helpers
that generate URLs, like some of the form helpers) as these are designed
- to work with segment based URLs.
+ to work with segment based URLs. \ No newline at end of file