Class TUrlMapping
TUrlMapping Class
The TUrlMapping module allows PRADO to construct and recognize URLs based on specific patterns.
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 through
<span class="php-var">$this</span>->Request[<span
class="php-quote">'paramname'</span>]
).
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.
Since it is derived from TUrlManager
, it should be configured
globally in the application configuration like the following,
<module id="request" class="THttpRequest" UrlManager="friendly-url" /> <module id="friendly-url" class="System.Web.TUrlMapping" EnableCustomUrl="true"> <url ServiceParameter="Posts.ViewPost" pattern="post/{id}/" parameters.id="\d+" /> <url ServiceParameter="Posts.ListPost" pattern="archive/{time}/" parameters.time="\d{6}" /> <url ServiceParameter="Posts.ListPost" pattern="category/{cat}/" parameters.cat="\d+" /> </module>
In the above, each <url> element specifies a URL pattern
represented as a TUrlMappingPattern
internally. You may create your own
pattern classes by extending TUrlMappingPattern
and specifying the
<class> attribute in the element.
The patterns can be also be specified in an external file using the setConfigFile ConfigFile property.
The URL mapping are evaluated in order, only the first mapping 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.
Only the PATH_INFO part of the URL is used to match the available patterns. The matching is strict in the sense that the whole pattern must match the whole PATH_INFO of the URL.
From PRADO v3.1.1, TUrlMapping also provides support for constructing URLs according to the specified pattern. You may enable this functionality by setting setEnableCustomUrl EnableCustomUrl to true. When you call THttpRequest::constructUrl() (or via TPageService::constructUrl()), TUrlMapping will examine the available URL mapping patterns using their TUrlMappingPattern::getServiceParameter ServiceParameter and TUrlMappingPattern::getPattern Pattern properties. A pattern is applied if its TUrlMappingPattern::getServiceParameter ServiceParameter matches the service parameter passed to constructUrl() and every parameter in the getPattern Pattern is found in the GET variables.
- TComponent
-
TApplicationComponent
-
TModule implements IModule
-
TUrlManager
-
TUrlMapping
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Wei Zhuo <weizhuo[at]gmail[dot]com>
Since: 3.0.5
Located at Web/TUrlMapping.php
public
|
|
protected
|
|
public
boolean
|
#
getEnableCustomUrl( )
Returns a value indicating whether to enable custom constructUrl. If true, constructUrl() will make use of the URL mapping rules to construct valid URLs. |
public
|
#
setEnableCustomUrl( boolean $value )
Sets a value indicating whether to enable custom constructUrl. If true, constructUrl() will make use of the URL mapping rules to construct valid URLs. |
public
string
|
|
public
|
|
public
string
|
|
public
|
|
public
string
|
|
public
|
#
setDefaultMappingClass( string $value )
Sets the default class of URL mapping patterns. When a URL matching pattern does not specify "class" attribute, it will default to the class specified by this property. You may use either a class name or a namespace format of class (if the class needs to be included first.) |
protected
|
|
public
array
|
#
parseUrl( )
Parses the request URL and returns an array of input parameters. This method overrides the parent implementation. The input parameters do not include GET and POST variables. This method uses the request URL path to find the first matching pattern. If found the matched pattern parameters are used to return as the input parameters. |
public
string
|
#
constructUrl( string $serviceID, string $serviceParam, array $getItems, boolean $encodeAmpersand, boolean $encodeGetItems )
Constructs a URL that can be recognized by PRADO. |
public
|
getID(),
setID()
|
getApplication(),
getRequest(),
getResponse(),
getService(),
getSession(),
getUser(),
publishAsset(),
publishFilePath()
|
GLOBAL_RAISE_EVENT_LISTENER
|
protected
|
$_patterns | array() |
#
list of patterns. |
protected
array
|
$_constructRules | array() |
#
rules for constructing URLs |