From 2143fc9d208c82a43cf9ea39f13c724e99f66d16 Mon Sep 17 00:00:00 2001 From: xue <> Date: Sat, 11 Aug 2007 14:30:07 +0000 Subject: further enhanced TUrlMapping. --- .../protected/pages/Configurations/UrlMapping.page | 77 ++++++++++++---------- 1 file changed, 42 insertions(+), 35 deletions(-) (limited to 'demos/quickstart/protected/pages') diff --git a/demos/quickstart/protected/pages/Configurations/UrlMapping.page b/demos/quickstart/protected/pages/Configurations/UrlMapping.page index 4e06dd09..3197dde3 100644 --- a/demos/quickstart/protected/pages/Configurations/UrlMapping.page +++ b/demos/quickstart/protected/pages/Configurations/UrlMapping.page @@ -4,36 +4,29 @@ -

Using the TUrlMapping module different URLs can be -mapped into any existing Prado pages or services. This allows -the application to use nice looking and friendly URLs. +

+The TUrlMapping module allows PRADO to construct and recognize friendly URLs +based on specific patterns.

-The TUrlMapping module allows aributary URL path to be mapped to a -particular service and page class. This module must be configured -before a service is initialized, thus this module should be configured -globally in the application configuration -file and before any services. +TUrlMapping consists of a list of URL patterns which are used to match +against the currently requested URL. The first matching pattern will then +be used to decompose the URL into request parameters (accessible via +$this->Request['paramname']). The patterns can also be used to +construct customized URLs. In this case, the parameters in an applied +pattern will be replaced with the corresponding GET variable values.

-
Info: -The TUrlMapping must be configured before the -Request module resolves the request. -This usually means delcaring the TUrlMapping module before any -<services> tag in the application configuration. -Specifying the mappings in the per directory config.xml is not supported. -
-

To use TUrlMapping, one must set the UrlManager property of the THttpRequest module as the TUrlMapping module ID. See following for an example, - - - + + + @@ -49,9 +42,18 @@ The above example is part of the application configuration of the blog

-The ServiceParameter and ServiceID (the default ID is 'page') set the service parameter and service ID, respectively, of the Request module. The service parameter for the TPageService service is the Page class name, e.g., for an URL "index.php?page=Home", "page" is the service ID and the service parameter is "Home". Other services may use the service parameter and ID differently. See Services for further details. +The ServiceParameter and ServiceID (the default ID is 'page') +set the service parameter and service ID, respectively, of the Request module. The service parameter for the TPageService service is the Page class name, e.g., for an URL "index.php?page=Home", "page" is the service ID and the service parameter is "Home". Other services may use the service parameter and ID differently. See Services for further details.

+
Info: +The TUrlMapping must be configured before the +request module resolves the request. +This means delcaring the TUrlMapping outside of the +<services> element in the application configuration. +Specifying the mappings in the per directory config.xml is not supported. +
+

Specifying URL Patterns

TUrlMapping enables recognition of customized URL formats based on a list prespecified of URL patterns. Each pattern is specified in a <url> tag. @@ -63,7 +65,7 @@ values are regular expression patterns that determine the mapping criteria. The Pattern property takes a regular expression with parameter names enclosed between a left brace '{' and a right brace '}'. The pattens for each parameter can be set -using Parametersattribute collection. +using Parameters attribute collection. For example, The example is equivalent to the following regular expression (it uses the "named group" feature in regular expressions available in PHP): - -\d{4})\/(?P\d{2})\/(?P\d+)/u -]]> - +

In the above example, the pattern contains 3 parameters named "year", @@ -93,13 +92,13 @@ property you need to escape the slash in regular expressions.

Following from the above pattern example, -an URL "http://example.com/index.php/articles/2006/07/21" will be matched -and valid. However, "http://example.com/index.php/articles/2006/07/hello" is not - valid since the "day" parameter pattern is not satisfied. - In the default TUrlMappingPattern class, the pattern is matched against the -path property of the URL only. For example, only the -"/index.php/articles/2006/07/21" portion of the URL is considered. -

+an URL http://example.com/index.php/articles/2006/07/21 will be matched +and valid. However, http://example.com/index.php/articles/2006/07/hello is not +valid since the day parameter pattern is not satisfied. +In the default TUrlMappingPattern class, the pattern is matched against the +PATH_INFO part of the URL only. For example, only the /articles/2006/07/21 +portion of the URL is considered. +

The mapped request URL is equivalent to index.php?page=ArticleView&year=2006&month=07&day=21. @@ -107,14 +106,22 @@ The request parameter values are available through the standard Request object. For example, $this->Request['year'].

-

The URL mapping are evaluated in order they are place and only the first mapping that matches +

The URL mapping are evaluated in order they are placed and only the first pattern that matches the URL will be used. Cascaded mapping can be achieved by placing the URL mappings in particular order. For example, placing the most specific mappings first.

Constructing Customized URLs

-Since version 3.0.6, TUrlMapping starts to support constructing customized URL formats. This is achieved by allowing users to extend TUrlMapping class and override the constructUrl method. In the applications, users can still use THttpRequest.constructUrl() or TPageService.constructUrl() to generate PRADO-recognizable URLS. The actual URL construction work is ultimately delegated to the TUrlMapping.constructUrl(), provided it is implemented. +Since version 3.1.1, TUrlMapping starts to support constructing customized URLs based on the provided patterns. To enable this feature, set TUrlMapping.EnableCustomUrl to true. When THttpRequest.constrcutUrl() is invoked, the actual URL construction work will be delegated to a matching TUrlMappingPattern instance. It replaces the parameters in the pattern with the corresponding GET variables passed to constructUrl(). +

+ +

+A matching pattern is one whose ServiceID and ServiceParameter properties are the same as those passed to constructUrl() and whose named parameters are found in the GET variables. For example, constructUrl('Posts.ListPost',array('cat'=>2)) will use the third pattern in the above example. +

+ +

+By default, TUrlMapping will construct URLs prefixed with the currently requesting PHP script path, such as /path/to/index.php/article/3. Users may change this behavior by explicitly specifying the URL prefix through its UrlPrefix property. For example, if the Web server configuration treats index.php as the default script, we can set UrlPrefix as /path/to and the constructed URL will look like /path/to/article/3.

$Id$
\ No newline at end of file -- cgit v1.2.3