Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml


Classes:
Keyword

Class TUrlMapping

TComponent
   |
   --TApplicationComponent
      |
      --TModule
         |
         --TUrlManager
            |
            --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

  1. $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.

Since it is derived from TUrlManager, it should be configured globally in the application configuration like the following,

  1. <module id="request" class="THttpRequest" UrlManager="friendly-url" />
  2. <module id="friendly-url" class="System.Web.TUrlMapping" EnableCustomUrl="true">
  3. <url ServiceParameter="Posts.ViewPost" pattern="post/{id}/" parameters.id="\d+" />
  4. <url ServiceParameter="Posts.ListPost" pattern="archive/{time}/" parameters.time="\d{6}" />
  5. <url ServiceParameter="Posts.ListPost" pattern="category/{cat}/" parameters.cat="\d+" />
  6. </module>

In the above, each <tt>&lt;url&gt;</tt> element specifies a URL pattern represented as a TUrlMappingPattern internally. You may create your own pattern classes by extending TUrlMappingPattern and specifying the <tt>&lt;class&gt;</tt> attribute in the element.

The patterns can be also be specified in an external file using the 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 EnableCustomUrl to true. When you call THttpRequest::constructUrl() (or via TPageService::constructUrl()), TUrlMapping will examine the available URL mapping patterns using their TUrlMappingPattern::getServiceParameter and TUrlMappingPattern::getPattern properties. A pattern is applied if its TUrlMappingPattern::getServiceParameter matches the service parameter passed to constructUrl() and every parameter in the getPattern is found in the GET variables.

Since: 3.0.5
Author: Wei Zhuo <weizhuo[at]gmail[dot]com>

Method Summary
string
constructUrl ( string $serviceID, string $serviceParam, array $getItems, boolean $encodeAmpersand, boolean $encodeGetItems)
Constructs a URL that can be recognized by PRADO.
string
string
boolean
Returns a value indicating whether to enable custom constructUrl.
TUrlMappingPattern
string
void
init ( TXmlElement $xml)
Initializes this module.
protected  void
Initialize the module from configuration file.
protected  void
Load and configure each url mapping pattern.
array
Parses the request URL and returns an array of input parameters.
void
setConfigFile ( string $value)
void
setDefaultMappingClass ( string $value)
Sets the default class of URL mapping patterns.
void
setEnableCustomUrl ( boolean $value)
Sets a value indicating whether to enable custom constructUrl.
void
setUrlPrefix ( string $value)
Methods Inherited From TUrlManager
TUrlManager::constructUrl(), TUrlManager::parseUrl()
Methods Inherited From TModule
TModule::getID(), TModule::init(), TModule::setID()
Methods Inherited From TApplicationComponent
TApplicationComponent::getApplication(), TApplicationComponent::getRequest(), TApplicationComponent::getResponse(), TApplicationComponent::getService(), TApplicationComponent::getSession(), TApplicationComponent::getUser(), TApplicationComponent::publishAsset(), TApplicationComponent::publishFilePath()
Methods Inherited From TComponent
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()

Constant Summary
string CONFIG_FILE_EXT File extension of external configuration file

Method Details

constructUrl

public string constructUrl (string $serviceID , string $serviceParam , array $getItems , boolean $encodeAmpersand , boolean $encodeGetItems )

Constructs a URL that can be recognized by PRADO.

This method provides the actual implementation used by THttpRequest::constructUrl. Override this method if you want to provide your own way of URL formatting. If you do so, you may also need to override parseUrl so that the URL can be properly parsed.

The URL is constructed as the following format: /entryscript.php?serviceID=serviceParameter&get1=value1&... If THttpRequest::setUrlFormat is 'Path', the following format is used instead: /entryscript.php/serviceID/serviceParameter/get1,value1/get2,value2...

Input
string$serviceIDservice ID
string$serviceParamservice parameter
array$getItemsGET parameters, null if not provided
boolean$encodeAmpersandwhether to encode the ampersand in URL
boolean$encodeGetItemswhether to encode the GET parameters (their names and values)
Output
string URL
Exception

getConfigFile

public string getConfigFile ()

Output
string external configuration file. Defaults to null.
Exception

getDefaultMappingClass

public string getDefaultMappingClass ()

Output
string the default class of URL mapping patterns. Defaults to TUrlMappingPattern.
Exception

getEnableCustomUrl

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.

Output
boolean whether to enable custom constructUrl. Defaults to false.
Exception

getMatchingPattern

public TUrlMappingPattern getMatchingPattern ()

Output
TUrlMappingPattern the matched pattern, null if not found.
Exception

getUrlPrefix

public string getUrlPrefix ()

Output
string the part that will be prefixed to the constructed URLs. Defaults to the requested script path (e.g. /path/to/index.php for a URL http://hostname/path/to/index.php)
Exception

init

public void init (TXmlElement $xml )

Initializes this module.

This method is required by the IModule interface.

Input
TXmlElement$xmlconfiguration for this module, can be null
Output
Exception
throwsTConfigurationException if module is configured in the global scope.

loadConfigFile

protected void loadConfigFile ()

Initialize the module from configuration file.

Output
Exception
throwsTConfigurationException if ConfigFile is invalid.

loadUrlMappings

protected void loadUrlMappings (TXmlElement $xml )

Load and configure each url mapping pattern.

Input
TXmlElement$xmlconfiguration node
Output
Exception
throwsTConfigurationException if specific pattern class is invalid

parseUrl

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.

Output
array list of input parameters
Exception

setConfigFile

public void setConfigFile (string $value )

Input
string$valueexternal configuration file in namespace format. The file must be suffixed with '.xml'.
Output
Exception
throwsTInvalidDataValueException if the file is invalid.

setDefaultMappingClass

public void 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.)

Input
string$valuethe default class of URL mapping patterns.
Output
Exception

setEnableCustomUrl

public void 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.

Input
boolean$valuewhether to enable custom constructUrl.
Output
Exception

setUrlPrefix

public void setUrlPrefix (string $value )

Input
string$valuethe part that will be prefixed to the constructed URLs. This is used by constructUrl() when EnableCustomUrl is set true.
Output
Exception


Constant Details

CONFIG_FILE_EXT

File extension of external configuration file

Type:

string

Value:

'.xml'