From cf168303ead21d1c8ad89af01458806e6be197fd Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Mon, 6 Aug 2012 17:10:17 +0100 Subject: Updated documentation --- user_guide_src/source/general/routing.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'user_guide_src/source/general/routing.rst') diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst index 45950fc11..6bb5bdbc5 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -106,6 +106,16 @@ call the shirts controller class and the id_123 function. You can also mix and match wildcards with regular expressions. +Callbacks +========= + +If you are using PHP >= 5.3 you can use callbacks in place of the normal routing +rules to process the back-references. Example:: + + $route['products/([a-z]+)/edit/(\d+)'] = function($product_type, $id){ + return "catalog/product_edit/" . strtolower($product_type) . "/" . $id; + }; + Reserved Routes =============== -- cgit v1.2.3-24-g4f1b From f002c2a825ccf6785e3867b4ecb92fe6013d364f Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Thu, 30 Aug 2012 13:56:01 +0200 Subject: Corrected styling errors in documentation --- user_guide_src/source/general/routing.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'user_guide_src/source/general/routing.rst') diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst index 6bb5bdbc5..0a16e13af 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -112,7 +112,8 @@ Callbacks If you are using PHP >= 5.3 you can use callbacks in place of the normal routing rules to process the back-references. Example:: - $route['products/([a-z]+)/edit/(\d+)'] = function($product_type, $id){ + $route['products/([a-z]+)/edit/(\d+)'] = function ($product_type, $id) + { return "catalog/product_edit/" . strtolower($product_type) . "/" . $id; }; -- cgit v1.2.3-24-g4f1b From 8f1cdd1904d9f8da9e9cbd383e4385740cc6951b Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Thu, 30 Aug 2012 13:57:54 +0200 Subject: Changed spaces to tabs where appropriate. --- user_guide_src/source/general/routing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source/general/routing.rst') diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst index 0a16e13af..edbc735c4 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -113,7 +113,7 @@ If you are using PHP >= 5.3 you can use callbacks in place of the normal routing rules to process the back-references. Example:: $route['products/([a-z]+)/edit/(\d+)'] = function ($product_type, $id) - { + { return "catalog/product_edit/" . strtolower($product_type) . "/" . $id; }; -- cgit v1.2.3-24-g4f1b From a9d98ceae9ebec711af9801dce7e43e85d5dcdc1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 23 Oct 2012 10:05:31 +0300 Subject: [ci skip] Add a note about routes.php not being a filter --- user_guide_src/source/general/routing.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'user_guide_src/source/general/routing.rst') diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst index 45950fc11..c03937070 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -47,11 +47,16 @@ segment of the URL, and a number is found in the second segment, the You can match literal values or you can use two wildcard types: **(:num)** will match a segment containing only numbers. - **(:any)** will match a segment containing any character. +**(:any)** will match a segment containing any character. .. note:: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones. +.. note:: Route rules are not filters! Setting a rule of e.g. + 'foo/bar/(:num)' will not prevent controller *Foo* and method + *bar* to be called with a non-numeric value if that is a valid + route. + Examples ======== -- cgit v1.2.3-24-g4f1b From 7676c2d6761cb3cdeccf005c2a30140f0ba3ced5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 30 Oct 2012 13:42:01 +0200 Subject: Fix issue #658 (:any wildcard matching slashes) --- user_guide_src/source/general/routing.rst | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'user_guide_src/source/general/routing.rst') diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst index c03937070..a6332c90c 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -29,7 +29,7 @@ Setting your own routing rules Routing rules are defined in your application/config/routes.php file. In it you'll see an array called $route that permits you to specify your own routing criteria. Routes can either be specified using wildcards or -Regular Expressions +Regular Expressions. Wildcards ========= @@ -47,7 +47,11 @@ segment of the URL, and a number is found in the second segment, the You can match literal values or you can use two wildcard types: **(:num)** will match a segment containing only numbers. -**(:any)** will match a segment containing any character. +**(:any)** will match a segment containing any character (except for '/', which is the segment delimiter). + +.. note:: Wildcards are actually aliases for regular expressions, with + **:any** being translated to **[^/]+** and **:num** to **[0-9]+**, + respectively. .. note:: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones. @@ -104,12 +108,28 @@ rules. Any valid regular expression is allowed, as are back-references. A typical RegEx route might look something like this:: - $route['products/([a-z]+)/(\d+)'] = "$1/id_$2"; + $route['products/([a-z]+)/(\d+)'] = '$1/id_$2'; In the above example, a URI similar to products/shirts/123 would instead -call the shirts controller class and the id_123 function. +call the shirts controller class and the id_123 method. + +With regular expressions, you can also catch a segment containing a +forward slash ('/'), which would usually represent the delimiter between +multiple segments. +For example, if a user accesses a password protected area of your web +application and you wish to be able to redirect them back to the same +page after they log in, you may find this example useful:: + + $route['login/(.+)'] = 'auth/login/$1'; + +That will call the auth controller class and its ``login()`` method, +passing everything contained in the URI after *login/* as a parameter. + +For those of you who don't know regular expressions and want to learn +more about them, `regular-expressions.info ` +might be a good starting point. -You can also mix and match wildcards with regular expressions. +..note:: You can also mix and match wildcards with regular expressions. Reserved Routes =============== -- cgit v1.2.3-24-g4f1b From d1097a1dc30f40c68bc4a5c89d3fadb295c55e56 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 19:55:42 +0200 Subject: Allow use of dashes in controller/method URI segments Supersedes PR #642 --- user_guide_src/source/general/routing.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'user_guide_src/source/general/routing.rst') 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 -- cgit v1.2.3-24-g4f1b From 16a704ce8a1449cbee22fb13bd32508c975fac9f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Nov 2012 17:25:00 +0200 Subject: [ci skip] Polish docs in user_guide_src/source/general/ --- user_guide_src/source/general/routing.rst | 50 +++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'user_guide_src/source/general/routing.rst') diff --git a/user_guide_src/source/general/routing.rst b/user_guide_src/source/general/routing.rst index e6174cc0d..2a0332088 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -9,34 +9,34 @@ normally follow this pattern:: example.com/class/function/id/ In some instances, however, you may want to remap this relationship so -that a different class/function can be called instead of the one +that a different class/method can be called instead of the one corresponding to the URL. -For example, lets say you want your URLs to have this prototype: +For example, lets say you want your URLs to have this prototype:: -example.com/product/1/ -example.com/product/2/ -example.com/product/3/ -example.com/product/4/ + example.com/product/1/ + example.com/product/2/ + example.com/product/3/ + example.com/product/4/ -Normally the second segment of the URL is reserved for the function -name, but in the example above it instead has a product ID. To overcome -this, CodeIgniter allows you to remap the URI handler. +Normally the second segment of the URL is reserved for the method +name, but in the example above it instead has a product ID. To +overcome this, CodeIgniter allows you to remap the URI handler. Setting your own routing rules ============================== -Routing rules are defined in your application/config/routes.php file. In -it you'll see an array called $route that permits you to specify your -own routing criteria. Routes can either be specified using wildcards or -Regular Expressions. +Routing rules are defined in your *application/config/routes.php* file. +In it you'll see an array called ``$route`` that permits you to specify +your own routing criteria. Routes can either be specified using wildcards +or Regular Expressions. Wildcards ========= A typical wildcard route might look something like this:: - $route['product/:num'] = "catalog/product_lookup"; + $route['product/:num'] = 'catalog/product_lookup'; In a route, the array key contains the URI to be matched, while the array value contains the destination it should be re-routed to. In the @@ -66,21 +66,21 @@ Examples Here are a few routing examples:: - $route['journals'] = "blogs"; + $route['journals'] = 'blogs'; A URL containing the word "journals" in the first segment will be remapped to the "blogs" class. :: - $route['blog/joe'] = "blogs/users/34"; + $route['blog/joe'] = 'blogs/users/34'; A URL containing the segments blog/joe will be remapped to the "blogs" class and the "users" method. The ID will be set to "34". :: - $route['product/(:any)'] = "catalog/product_lookup"; + $route['product/(:any)'] = 'catalog/product_lookup'; A URL with "product" as the first segment, and anything in the second will be remapped to the "catalog" class and the "product_lookup" @@ -88,12 +88,12 @@ method. :: - $route['product/(:num)'] = "catalog/product_lookup_by_id/$1"; + $route['product/(:num)'] = 'catalog/product_lookup_by_id/$1'; A URL with "product" as the first segment, and a number in the second will be remapped to the "catalog" class and the "product_lookup_by_id" method passing in the match as a variable to -the function. +the method. .. important:: Do not use leading/trailing slashes. @@ -111,7 +111,7 @@ A typical RegEx route might look something like this:: $route['products/([a-z]+)/(\d+)'] = '$1/id_$2'; In the above example, a URI similar to products/shirts/123 would instead -call the shirts controller class and the id_123 method. +call the "shirts" controller class and the "id_123" method. With regular expressions, you can also catch a segment containing a forward slash ('/'), which would usually represent the delimiter between @@ -122,7 +122,7 @@ page after they log in, you may find this example useful:: $route['login/(.+)'] = 'auth/login/$1'; -That will call the auth controller class and its ``login()`` method, +That will call the "auth" controller class and its ``login()`` method, passing everything contained in the URI after *login/* as a parameter. For those of you who don't know regular expressions and want to learn @@ -134,12 +134,12 @@ might be a good starting point. Callbacks ========= -If you are using PHP >= 5.3 you can use callbacks in place of the normal routing -rules to process the back-references. Example:: +If you are using PHP >= 5.3 you can use callbacks in place of the normal +routing rules to process the back-references. Example:: $route['products/([a-z]+)/edit/(\d+)'] = function ($product_type, $id) { - return "catalog/product_edit/" . strtolower($product_type) . "/" . $id; + return 'catalog/product_edit/' . strtolower($product_type) . '/' . $id; }; Reserved Routes @@ -161,7 +161,7 @@ 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 +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*. -- cgit v1.2.3-24-g4f1b