Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • ActionFormModelBase
  • CActiveDataProvider
  • CalendarEventFormModel
  • CallFormModel
  • CArrayDataProvider
  • CAssetManager
  • CBaseController
  • CBaseUrlRule
  • CCacheHttpSession
  • CClientScript
  • CController
  • CCookieCollection
  • CDataProvider
  • CDataProviderIterator
  • CDbHttpSession
  • CExtController
  • CFormModel
  • CHttpCookie
  • CHttpRequest
  • CHttpSession
  • CHttpSessionIterator
  • COutputEvent
  • CPagination
  • CreatePageFormModel
  • CSort
  • CSqlDataProvider
  • CTheme
  • CThemeManager
  • CUploadedFile
  • CUrlManager
  • CUrlRule
  • CWebApplication
  • CWebModule
  • CWidgetFactory
  • EditMobileFormsFormModel
  • EventCommentPublisherFormModel
  • EventFormModel
  • EventPublisherFormModel
  • FileSystemObjectDataProvider
  • MassActionFormModel
  • MobilePagination
  • NoteFormModel
  • NotificationsController
  • TimeFormModel
  • UploadLogoFormModel
  • X2FormModel
  • X2HttpRequest

Interfaces

  • IDataProvider
  • IWidgetFactory
  • Overview
  • Package
  • Class
  • Tree

Class CUrlManager

CUrlManager manages the URLs of Yii Web applications.

It provides URL construction (CUrlManager::createUrl()) as well as parsing (CUrlManager::parseUrl()) functionality.

URLs managed via CUrlManager can be in one of the following two formats, by setting setUrlFormat urlFormat property:
  • 'path' format: /path/to/EntryScript.php/name1/value1/name2/value2...
  • 'get' format: /path/to/EntryScript.php?name1=value1&name2=value2...
When using 'path' format, CUrlManager uses a set of setRules rules to:
  • parse the requested URL into a route ('ControllerID/ActionID') and GET parameters;
  • create URLs based on the given route and GET parameters.

A rule consists of a route and a pattern. The latter is used by CUrlManager to determine which rule is used for parsing/creating URLs. A pattern is meant to match the path info part of a URL. It may contain named parameters using the syntax '<ParamName:RegExp>'.

When parsing a URL, a matching rule will extract the named parameters from the path info and put them into the $_GET variable; when creating a URL, a matching rule will extract the named parameters from $_GET and put them into the path info part of the created URL.

If a pattern ends with '/*', it means additional GET parameters may be appended to the path info part of the URL; otherwise, the GET parameters can only appear in the query string part.

To specify URL rules, set the setRules rules property as an array of rules (pattern=>route). For example,

array(
    'articles'=>'article/list',
    'article/<id:\d+>/*'=>'article/read',
)
Two rules are specified in the above:
  • The first rule says that if the user requests the URL '/path/to/index.php/articles', it should be treated as '/path/to/index.php/article/list'; and vice versa applies when constructing such a URL.
  • The second rule contains a named parameter 'id' which is specified using the <ParamName:RegExp> syntax. It says that if the user requests the URL '/path/to/index.php/article/13', it should be treated as '/path/to/index.php/article/read?id=13'; and vice versa applies when constructing such a URL.

The route part may contain references to named parameters defined in the pattern part. This allows a rule to be applied to different routes based on matching criteria. For example,

array(
     '<_c:(post|comment)>/<id:\d+>/<_a:(create|update|delete)>'=>'<_c>/<_a>',
     '<_c:(post|comment)>/<id:\d+>'=>'<_c>/view',
     '<_c:(post|comment)>s/*'=>'<_c>/list',
)

In the above, we use two named parameters '<_c>' and '<_a>' in the route part. The '<_c>' parameter matches either 'post' or 'comment', while the '<_a>' parameter matches an action ID.

Like normal rules, these rules can be used for both parsing and creating URLs. For example, using the rules above, the URL '/index.php/post/123/create' would be parsed as the route 'post/create' with GET parameter 'id' being 123. And given the route 'post/list' and GET parameter 'page' being 2, we should get a URL '/index.php/posts/page/2'.

It is also possible to include hostname into the rules for parsing and creating URLs. One may extract part of the hostname to be a GET parameter. For example, the URL http:<span class="php-comment">//admin.example.com/en/profile</span> may be parsed into GET parameters user=admin and lang=en. On the other hand, rules with hostname may also be used to create URLs with parameterized hostnames.

In order to use parameterized hostnames, simply declare URL rules with host info, e.g.:

array(
    'http://<user:\w+>.example.com/<lang:\w+>/profile' => 'user/profile',
)

Starting from version 1.1.8, one can write custom URL rule classes and use them for one or several URL rules. For example,

array(
  // a standard rule
  '<action:(login|logout)>' => 'site/<action>',
  // a custom rule using data in DB
  array(
    'class' => 'application.components.MyUrlRule',
    'connectionID' => 'db',
  ),
)
Please note that the custom URL rule class should extend from CBaseUrlRule and implement the following two methods,
  • CBaseUrlRule::createUrl()
  • CBaseUrlRule::parseUrl()

CUrlManager is a default application component that may be accessed via CApplication::getUrlManager().

CComponent
Extended by CApplicationComponent implements IApplicationComponent
Extended by CUrlManager

Direct known subclasses

X2UrlManager
Package: system\web
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/web/CUrlManager.php
Methods summary
public
# init( )

Initializes the application component.

Initializes the application component.

Overrides

CApplicationComponent::init()
protected
# processRules( )

Processes the URL rules.

Processes the URL rules.

public
# addRules( array $rules, boolean $append = true )

Adds new URL rules. In order to make the new rules effective, this method must be called BEFORE CWebApplication::processRequest().

Adds new URL rules. In order to make the new rules effective, this method must be called BEFORE CWebApplication::processRequest().

Parameters

$rules
array
$rules new URL rules (pattern=>route).
$append
boolean
$append whether the new URL rules should be appended to the existing ones. If false, they will be inserted at the beginning.

Since

1.1.4
protected CUrlRule
# createUrlRule( mixed $route, string $pattern )

Creates a URL rule instance. The default implementation returns a CUrlRule object.

Creates a URL rule instance. The default implementation returns a CUrlRule object.

Parameters

$route
mixed
$route the route part of the rule. This could be a string or an array
$pattern
string
$pattern the pattern part of the rule

Returns

CUrlRule
the URL rule instance

Since

1.1.0
public string
# createUrl( string $route, array $params = array(), string $ampersand = '&' )

Constructs a URL.

Constructs a URL.

Parameters

$route
string
$route the controller and the action (e.g. article/read)
$params
array
$params list of GET parameters (name=>value). Both the name and value will be URL-encoded. If the name is '#', the corresponding value will be treated as an anchor and will be appended at the end of the URL.
$ampersand
string
$ampersand the token separating name-value pairs in the URL. Defaults to '&'.

Returns

string
the constructed URL
protected string
# createUrlDefault( string $route, array $params, string $ampersand )

Creates a URL based on default settings.

Creates a URL based on default settings.

Parameters

$route
string
$route the controller and the action (e.g. article/read)
$params
array
$params list of GET parameters
$ampersand
string
$ampersand the token separating name-value pairs in the URL.

Returns

string
the constructed URL
public string
# parseUrl( CHttpRequest $request )

Parses the user request.

Parses the user request.

Parameters

$request
CHttpRequest
$request the request application component

Returns

string
the route (controllerID/actionID) and perhaps GET parameters in path format.
public
# parsePathInfo( string $pathInfo )

Parses a path info into URL segments and saves them to $_GET and $_REQUEST.

Parses a path info into URL segments and saves them to $_GET and $_REQUEST.

Parameters

$pathInfo
string
$pathInfo path info
public string
# createPathInfo( array $params, string $equal, string $ampersand, string $key = null )

Creates a path info based on the given parameters.

Creates a path info based on the given parameters.

Parameters

$params
array
$params list of GET parameters
$equal
string
$equal the separator between name and value
$ampersand
string
$ampersand the separator between name-value pairs
$key
string
$key this is used internally.

Returns

string
the created path info
public string
# removeUrlSuffix( string $pathInfo, string $urlSuffix )

Removes the URL suffix from path info.

Removes the URL suffix from path info.

Parameters

$pathInfo
string
$pathInfo path info part in the URL
$urlSuffix
string
$urlSuffix the URL suffix to be removed

Returns

string
path info with URL suffix removed.
public string
# getBaseUrl( )

Returns the base URL of the application.

Returns the base URL of the application.

Returns

string
the base URL of the application (the part after host name and before query string). If CUrlManager::$showScriptName is true, it will include the script name part. Otherwise, it will not, and the ending slashes are stripped off.
public
# setBaseUrl( string $value )

Sets the base URL of the application (the part after host name and before query string). This method is provided in case the baseUrl cannot be determined automatically. The ending slashes should be stripped off. And you are also responsible to remove the script name if you set CUrlManager::$showScriptName to be false.

Sets the base URL of the application (the part after host name and before query string). This method is provided in case the baseUrl cannot be determined automatically. The ending slashes should be stripped off. And you are also responsible to remove the script name if you set CUrlManager::$showScriptName to be false.

Parameters

$value
string
$value the base URL of the application

Since

1.1.1
public string
# getUrlFormat( )

Returns the URL format.

Returns the URL format.

Returns

string
the URL format. Defaults to 'path'. Valid values include 'path' and 'get'. Please refer to the guide for more details about the difference between these two formats.
public
# setUrlFormat( string $value )

Sets the URL format.

Sets the URL format.

Parameters

$value
string
$value the URL format. It must be either 'path' or 'get'.
Methods inherited from CApplicationComponent
getIsInitialized()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Constants summary
string CACHE_KEY 'Yii.CUrlManager.rules'
#
string GET_FORMAT 'get'
#
string PATH_FORMAT 'path'
#
Properties summary
public array $rules array()
#

the URL rules (pattern=>route).

the URL rules (pattern=>route).

public string $urlSuffix ''
#

the URL suffix used when in 'path' format. For example, ".html" can be used so that the URL looks like pointing to a static HTML page. Defaults to empty.

the URL suffix used when in 'path' format. For example, ".html" can be used so that the URL looks like pointing to a static HTML page. Defaults to empty.

public boolean $showScriptName true
#

whether to show entry script name in the constructed URL. Defaults to true.

whether to show entry script name in the constructed URL. Defaults to true.

public boolean $appendParams true
#

whether to append GET parameters to the path info part. Defaults to true. This property is only effective when urlFormat is 'path' and is mainly used when creating URLs. When it is true, GET parameters will be appended to the path info and separate from each other using slashes. If this is false, GET parameters will be in query part.

whether to append GET parameters to the path info part. Defaults to true. This property is only effective when urlFormat is 'path' and is mainly used when creating URLs. When it is true, GET parameters will be appended to the path info and separate from each other using slashes. If this is false, GET parameters will be in query part.

public string $routeVar 'r'
#

the GET variable name for route. Defaults to 'r'.

the GET variable name for route. Defaults to 'r'.

public boolean $caseSensitive true
#

whether routes are case-sensitive. Defaults to true. By setting this to false, the route in the incoming request will be turned to lower case first before further processing. As a result, you should follow the convention that you use lower case when specifying controller mapping (CWebApplication::$controllerMap) and action mapping (CController::actions()). Also, the directory names for organizing controllers should be in lower case.

whether routes are case-sensitive. Defaults to true. By setting this to false, the route in the incoming request will be turned to lower case first before further processing. As a result, you should follow the convention that you use lower case when specifying controller mapping (CWebApplication::$controllerMap) and action mapping (CController::actions()). Also, the directory names for organizing controllers should be in lower case.

public boolean $matchValue false
#

whether the GET parameter values should match the corresponding sub-patterns in a rule before using it to create a URL. Defaults to false, meaning a rule will be used for creating a URL only if its route and parameter names match the given ones. If this property is set true, then the given parameter values must also match the corresponding parameter sub-patterns. Note that setting this property to true will degrade performance.

whether the GET parameter values should match the corresponding sub-patterns in a rule before using it to create a URL. Defaults to false, meaning a rule will be used for creating a URL only if its route and parameter names match the given ones. If this property is set true, then the given parameter values must also match the corresponding parameter sub-patterns. Note that setting this property to true will degrade performance.

Since

1.1.0
public string $cacheID 'cache'
#

the ID of the cache application component that is used to cache the parsed URL rules. Defaults to 'cache' which refers to the primary cache application component. Set this property to false if you want to disable caching URL rules.

the ID of the cache application component that is used to cache the parsed URL rules. Defaults to 'cache' which refers to the primary cache application component. Set this property to false if you want to disable caching URL rules.

public boolean $useStrictParsing false
#

whether to enable strict URL parsing. This property is only effective when urlFormat is 'path'. If it is set true, then an incoming URL must match one of the rules URL rules. Otherwise, it will be treated as an invalid request and trigger a 404 HTTP exception. Defaults to false.

whether to enable strict URL parsing. This property is only effective when urlFormat is 'path'. If it is set true, then an incoming URL must match one of the rules URL rules. Otherwise, it will be treated as an invalid request and trigger a 404 HTTP exception. Defaults to false.

public string $urlRuleClass 'CUrlRule'
#

the class name or path alias for the URL rule instances. Defaults to 'CUrlRule'. If you change this to something else, please make sure that the new class must extend from CBaseUrlRule and have the same constructor signature as CUrlRule. It must also be serializable and autoloadable.

the class name or path alias for the URL rule instances. Defaults to 'CUrlRule'. If you change this to something else, please make sure that the new class must extend from CBaseUrlRule and have the same constructor signature as CUrlRule. It must also be serializable and autoloadable.

Since

1.1.8
Properties inherited from CApplicationComponent
$behaviors
Magic properties summary
public string $baseUrl
#

The base URL of the application (the part after host name and before query string). If CUrlManager::$showScriptName is true, it will include the script name part. Otherwise, it will not, and the ending slashes are stripped off.

The base URL of the application (the part after host name and before query string). If CUrlManager::$showScriptName is true, it will include the script name part. Otherwise, it will not, and the ending slashes are stripped off.

public string $urlFormat
#

The URL format. Defaults to 'path'. Valid values include 'path' and 'get'. Please refer to the guide for more details about the difference between these two formats.

The URL format. Defaults to 'path'. Valid values include 'path' and 'get'. Please refer to the guide for more details about the difference between these two formats.

Magic properties inherited from CApplicationComponent
$isInitialized
API documentation generated by ApiGen 2.8.0