From 0b58b3cad456efc5ecce89f622876c6b715439c2 Mon Sep 17 00:00:00 2001 From: Fatih Kalifa Date: Tue, 5 Nov 2013 15:36:40 +0700 Subject: Fix HTTP Verb Routing Rules Fix code style, removed (:any) rule in http verb to avoid confusion, and add proposed documentation and changelog --- user_guide_src/source/general/routing.rst | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 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 5520f59fe..6495f1ad4 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -142,6 +142,42 @@ routing rules to process the back-references. Example:: return 'catalog/product_edit/' . strtolower($product_type) . '/' . $id; }; +Using HTTP Verb in Routes +========================= + +If you prefer you can use HTTP Verb (or method) to define your routing rules. +This is particularly useful when building RESTful application. You can use standard HTTP +Verb (GET, PUT, POST, DELETE) or custom HTTP Verb (e.g: PURGE). HTTP Verb rule is case +insensitive. All you need to do is add array index using HTTP Verb rule. Example:: + + $route['products']['put'] = 'product/insert'; + +In the above example, a PUT request to URI "products" would call the "product" controller +class and "insert" method + +:: + + $route['products/(:num)']['DELETE'] = 'product/delete/$1'; + +A DELETE request to URL with "products" as first segment and a number in the second will be +remapped to the "product" class and "delete" method passing in the match as a variable to +the method. + +:: + + $route['products/([a-z]+)/(\d+)']['get'] = 'product/$1/$2'; + +A GET request to a URI similar to products/shirts/123 would call the "product" controller +class and "shirt" method with number as method parameter + +Using HTTP Verb is optional, so if you want any HTTP Verb to be handled in one rule +You could just write your routing rule without HTTP Verb. Example:: + + $route['product'] = 'product'; + +This way, all incoming request using any HTTP method containing the word "product" +in the first segment will be remapped to "product" class + Reserved Routes =============== -- cgit v1.2.3-24-g4f1b From c761a206def7714d18623d46b05adc2bbeedce21 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Nov 2013 14:02:15 +0200 Subject: Polish changes from PR #2712 --- user_guide_src/source/general/routing.rst | 37 ++++++++++--------------------- 1 file changed, 12 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 6495f1ad4..0b91d3fa9 100644 --- a/user_guide_src/source/general/routing.rst +++ b/user_guide_src/source/general/routing.rst @@ -142,41 +142,28 @@ routing rules to process the back-references. Example:: return 'catalog/product_edit/' . strtolower($product_type) . '/' . $id; }; -Using HTTP Verb in Routes -========================= +Using HTTP verbs in routes +========================== -If you prefer you can use HTTP Verb (or method) to define your routing rules. -This is particularly useful when building RESTful application. You can use standard HTTP -Verb (GET, PUT, POST, DELETE) or custom HTTP Verb (e.g: PURGE). HTTP Verb rule is case -insensitive. All you need to do is add array index using HTTP Verb rule. Example:: +It is possible to use HTTP verbs (request method) to define your routing rules. +This is particularly useful when building RESTful applications. You can use standard HTTP +verbs (GET, PUT, POST, DELETE, PATCH) or a custom one such (e.g. PURGE). HTTP verb rules +are case-insensitive. All you need to do is to add the verb as an array key to your route. +Example:: $route['products']['put'] = 'product/insert'; -In the above example, a PUT request to URI "products" would call the "product" controller -class and "insert" method +In the above example, a PUT request to URI "products" would call the ``Product::insert()`` +controller method. :: $route['products/(:num)']['DELETE'] = 'product/delete/$1'; -A DELETE request to URL with "products" as first segment and a number in the second will be -remapped to the "product" class and "delete" method passing in the match as a variable to -the method. - -:: - - $route['products/([a-z]+)/(\d+)']['get'] = 'product/$1/$2'; - -A GET request to a URI similar to products/shirts/123 would call the "product" controller -class and "shirt" method with number as method parameter - -Using HTTP Verb is optional, so if you want any HTTP Verb to be handled in one rule -You could just write your routing rule without HTTP Verb. Example:: - - $route['product'] = 'product'; +A DELETE request to URL with "products" as first the segment and a number in the second will be +mapped to the ``Product::delete()`` method, passing the numeric value as the first parameter. -This way, all incoming request using any HTTP method containing the word "product" -in the first segment will be remapped to "product" class +Using HTTP verbs is of course, optional. Reserved Routes =============== -- cgit v1.2.3-24-g4f1b