## Class TUrlMapping

Description

TUrlMapping Class

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 <tt>application.xml</tt> file and before any services.

      <module id="friendly-url" class="System.Web.TUrlMapping">
        <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>
      <module id="request" class="THttpRequest" UrlManager="friendly-url" />

See TUrlMappingPattern for details regarding the mapping patterns. Similar to other modules, the <tt>&lt;url /&gt;</tt> configuration class can be customised using the <tt>class</tt> 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.

The mapping can be load from an external file by specifying a configuration file using the ConfigFile property.

Since TUrlMapping is a URL manager extending from TUrlManager, you may override TUrlManager::constructUrl to support your pattern-based URL scheme.

- since: 3.0.5
- version: $Id: TUrlMapping.php 1551 2006-12-03 23:16:40Z xue $
- author: Wei Zhuo <weizhuo[at]gmail[dot]com>

Located in /Web/TUrlMapping.php (line 51)

    TComponent
       |
       --TApplicationComponent
          |
          --TModule
             |
             --TUrlManager
                |
                --TUrlMapping

Class Constant Summary
CONFIG_FILE_EXT = '.xml'
Method Summary
void changeServiceParameters (TUrlMappingPattern $pattern)
string getConfigFile ()
TUrlMappingPattern getMatchingPattern ()
void init (TXmlElement $xml)
void loadConfigFile ()
void loadUrlMappings (TXmlElement $xml)
array parseUrl ()
void setConfigFile (string $value)
Methods
changeServiceParameters (line 188)

- access: protected

void changeServiceParameters (TUrlMappingPattern $pattern)

- TUrlMappingPattern $pattern: change the Request service ID and page class.

getConfigFile (line 110)

- return: external configuration file. Defaults to null.
- access: public

string getConfigFile ()
getMatchingPattern (line 180)

- return: the matched pattern, null if not found.
- access: public

TUrlMappingPattern getMatchingPattern ()
init (line 80)

Initializes this module.

This method is required by the IModule interface.

- access: public
- throws: TConfigurationException if module is configured in the global scope.

void init (TXmlElement $xml)

- TXmlElement $xml: configuration for this module, can be null

Redefinition of:

TModule::init()
  Initializes the module.

loadConfigFile (line 94)

Initialize the module from configuration file.

- access: protected
- throws: TConfigurationException if ConfigFile is invalid.

void loadConfigFile ()
loadUrlMappings (line 131)

Load and configure each url mapping pattern.

- access: protected
- throws: TConfigurationException if specific pattern class is invalid

void loadUrlMappings (TXmlElement $xml)

- TXmlElement $xml: configuration node

parseUrl (line 157)

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.

- return: list of input parameters
- access: public

array parseUrl ()

Redefinition of:

TUrlManager::parseUrl()
  Parses the request URL and returns an array of input parameters.

setConfigFile (line 120)

- access: public
- throws: TInvalidDataValueException if the file is invalid.

void setConfigFile (string $value)

- string $value: external configuration file in namespace format. The file must be suffixed with '.xml'.

#### Inherited Methods

Inherited From TUrlManager

> TUrlManager::constructUrl()
> TUrlManager::parseUrl()

Inherited From TModule

> TModule::getID()
> TModule::init()
> TModule::setID()

Inherited From TApplicationComponent

> TApplicationComponent::getApplication()
> TApplicationComponent::getRequest()
> TApplicationComponent::getResponse()
> TApplicationComponent::getService()
> TApplicationComponent::getSession()
> TApplicationComponent::getUser()
> TApplicationComponent::publishAsset()
> TApplicationComponent::publishFilePath()

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()

Class Constants
CONFIG_FILE_EXT = '.xml' (line 56)

File extension of external configuration file

Documentation generated on Sun, 14 Jan 2007 21:44:56 -0500 by phpDocumentor 1.3.0RC4