TUrlMappingPattern class.
TUrlMappingPattern represents a pattern used to parse and construct URLs. If the currently requested URL matches the pattern, it will alter the THttpRequest parameters. If a constructUrl() call matches the pattern parameters, the pattern will generate a valid URL. In both case, only the PATH_INFO part of a URL is parsed/constructed using the pattern.
To specify the pattern, set the Pattern property. Pattern takes a string expression with parameter names enclosed between a left brace '{' and a right brace '}'. The patterns for each parameter can be set using Parameters attribute collection. For example
- <url ... pattern="articles/{year}/{month}/{day}"
- parameters.year="\d{4}" parameters.month="\d{2}" parameters.day="\d+" />
In the above example, the pattern contains 3 parameters named "year", "month" and "day". The pattern for these parameters are, respectively, "\d{4}" (4 digits), "\d{2}" (2 digits) and "\d+" (1 or more digits). Essentially, the <tt>Parameters</tt> attribute name and values are used as substrings in replacing the placeholders in the <tt>Pattern</tt> string to form a complete regular expression string.
For more complicated patterns, one may specify the pattern using a regular expression by RegularExpression. For example, the above pattern is equivalent to the following regular expression-based pattern:
The above regular expression used the "named group" feature available in PHP. Notice that you need to escape the slash in regular expressions.
- /^articles/(?P<year>d{4})/(?P<month>d{2})/(?P<day>d+)$/u
Thus, only an url that matches the pattern will be valid. For example, a URL <tt>http://example.com/index.php/articles/2006/07/21</tt> will match the above pattern, while <tt>http://example.com/index.php/articles/2006/07/hello</tt> will not since the "day" parameter pattern is not satisfied.
The parameter values are available through the <tt>THttpRequest</tt> instance (e.g. <tt>$this->Request['year']</tt>).
The ServiceParameter and ServiceID (the default ID is 'page') set the service parameter and service id respectively.
Located in /Web/TUrlMapping.php (line 374)
TComponent | --TUrlMappingPattern
Constructor.
Constructs a URL using this pattern.
Returns a value indicating whether to use this pattern to construct URL.
Substitute the parameter key value pairs as named groupings in the regular expression matching pattern.
Uses URL pattern (or full regular expression if available) to match the given url path.
Sets a value indicating whether to enable custom constructUrl using this pattern
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()
Documentation generated on Mon, 21 Apr 2008 11:36:40 -0400 by phpDocumentor 1.3.0RC4