PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

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
Extended by TApplicationComponent
Extended by TModule implements IModule
Extended by TUrlManager
Extended by TUrlMapping
Package: System\Web
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
Methods summary
public
# init( mixed $config )

Initializes this module. This method is required by the IModule interface.

Initializes this module. This method is required by the IModule interface.

Parameters

$config
mixed
configuration for this module, can be null

Throws

TConfigurationException
if module is configured in the global scope.

Overrides

TModule::init()
protected
# loadConfigFile( )

Initialize the module from configuration file.

Initialize the module from configuration file.

Throws

TConfigurationException
if getConfigFile ConfigFile is invalid.
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.

Returns a value indicating whether to enable custom constructUrl. If true, constructUrl() will make use of the URL mapping rules to construct valid URLs.

Returns

boolean
whether to enable custom constructUrl. Defaults to false.

Since

3.1.1
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.

Sets a value indicating whether to enable custom constructUrl. If true, constructUrl() will make use of the URL mapping rules to construct valid URLs.

Parameters

$value
boolean
whether to enable custom constructUrl.

Since

3.1.1
public string
# getUrlPrefix( )

Returns

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)

Since

3.1.1
public
# setUrlPrefix( string $value )

Parameters

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

Since

3.1.1

See

TUrlMapping::getUrlPrefix()
public string
# getConfigFile( )

Returns

string
external configuration file. Defaults to null.
public
# setConfigFile( string $value )

Parameters

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

Throws

TInvalidDataValueException
if the file is invalid.
public string
# getDefaultMappingClass( )

Returns

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

Since

3.1.1
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.)

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

Parameters

$value
string
the default class of URL mapping patterns.

Since

3.1.1
protected
# loadUrlMappings( mixed $config )

Load and configure each url mapping pattern.

Load and configure each url mapping pattern.

Parameters

$config
mixed
configuration node

Throws

TConfigurationException
if specific pattern class is invalid
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.

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.

Returns

array
list of input parameters

Overrides

TUrlManager::parseUrl()
public string
# constructUrl( string $serviceID, string $serviceParam, array $getItems, boolean $encodeAmpersand, boolean $encodeGetItems )

Constructs a URL that can be recognized by PRADO.

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 TUrlMapping::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 THttpRequest.UrlFormat is 'Path', the following format is used instead: /entryscript.php/serviceID/serviceParameter/get1,value1/get2,value2... If THttpRequest::setUrlFormat THttpRequest.UrlFormat is 'HiddenPath', the following format is used instead: /serviceID/serviceParameter/get1,value1/get2,value2...

Parameters

$serviceID
string
service ID
$serviceParam
string
service parameter
$getItems
array
GET parameters, null if not provided
$encodeAmpersand
boolean
whether to encode the ampersand in URL
$encodeGetItems
boolean
whether to encode the GET parameters (their names and values)

Returns

string
URL

Since

3.1.1

See

TUrlMapping::parseUrl()

Overrides

TUrlManager::constructUrl()
public TUrlMappingPattern
# getMatchingPattern( )

Returns

TUrlMappingPattern
the matched pattern, null if not found.
Methods inherited from TModule
getID(), setID()
Methods inherited from TApplicationComponent
getApplication(), getRequest(), getResponse(), getService(), getSession(), getUser(), publishAsset(), publishFilePath()
Methods inherited from TComponent
__call(), __construct(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Properties summary
protected TUrlMappingPattern[] $_patterns array()
#

list of patterns.

list of patterns.

protected array $_constructRules array()
#

rules for constructing URLs

rules for constructing URLs

Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO