PHP 클래스 Router

파일 보기 프로젝트 열기: baserproject/basercms 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$initialized boolean Have routes been loaded
$routes array Array of routes connected with Router::connect()

보호된 프로퍼티들

프로퍼티 타입 설명
$_currentRoute array The route matching the URL of the current request
$_fullBaseUrl string Contains the base string that will be applied to all generated URLs For example https://example.com
$_initialState array Initial state is populated the first time reload() is called which is at the bottom of this file. This is a cheat as get_class_vars() returns the value of static vars even if they have changed.
$_namedConfig string Stores all information necessary to decide what named arguments are parsed under what conditions.
$_namedExpressions array Named expressions
$_parseExtensions boolean Directive for Router to parse out file extensions for mapping to Content-types.
$_prefixes array Includes admin prefix
$_requests array This will contain more than one request object when requestAction is used.
$_resourceMap array Default HTTP request method => controller action map.
$_resourceMapped array List of resource-mapped controllers
$_routeClass string Default route class to use
$_validExtensions array List of valid extensions to parse from a URL. If null, any extension is allowed.

공개 메소드들

메소드 설명
connect ( string $route, array $defaults = [], array $options = [] ) : array Connects a new Route in the router.
connectNamed ( array $named, array $options = [] ) : array Specifies what named parameters CakePHP should be parsing out of incoming URLs. By default CakePHP will parse every named parameter out of incoming URLs. However, if you want to take more control over how named parameters are parsed you can use one of the following setups:
currentRoute ( ) : CakeRoute Returns the route matching the current request (useful for requestAction traces)
defaultRouteClass ( string $routeClass = null ) : string | null Set the default route class to use or return the current one
extensions ( ) : array Get the list of extensions that can be parsed by Router.
fullBaseUrl ( string $base = null ) : string Sets the full base URL that will be used as a prefix for generating fully qualified URLs for this application. If no parameters are passed, the currently configured value is returned.
getNamedExpressions ( ) : array Gets the named route elements for use in app/Config/routes.php
getParam ( string $name = 'controller', boolean $current = false ) : string | null Gets URL parameter by name
getParams ( boolean $current = false ) : array Gets parameter information
getPaths ( boolean $current = false ) : array Gets path information
getRequest ( boolean $current = false ) : CakeRequest | null Gets the current request object, or the first one.
mapResources ( string | array $controller, array $options = [] ) : array Creates REST resource routes for the given controller(s). When creating resource routes for a plugin, by default the prefix will be changed to the lower_underscore version of the plugin name. By providing a prefix you can override this behavior.
namedConfig ( ) : array Gets the current named parameter configuration values.
normalize ( array | string $url = '/' ) : string Normalizes a URL for purposes of comparison.
parse ( string $url ) : array Parses given URL string. Returns 'routing' parameters for that URL.
parseExtensions ( ) : void Instructs the router to parse out file extensions from the URL.
popRequest ( ) : CakeRequest Pops a request off of the request stack. Used when doing requestAction
prefixes ( ) : array Returns the list of prefixes used in connected routes
promote ( integer $which = null ) : boolean Promote a route (by default, the last one added) to the beginning of the list
queryString ( string | array $q, array $extra = [], boolean $escape = false ) : array Generates a well-formed querystring from $q
redirect ( string $route, array $url, array $options = [] ) : array Connects a new redirection Route in the router.
reload ( ) : void Reloads default Router settings. Resets all class variables and removes all connected routes.
requestRoute ( ) : CakeRoute Returns the route matching the current request URL.
resourceMap ( array $resourceMap = null ) : mixed Resource map getter & setter.
reverse ( CakeRequest | array $params, boolean $full = false ) : string Reverses a parsed parameter array into a string.
setExtensions ( array $extensions, boolean $merge = true ) : array Set/add valid extensions.
setRequestInfo ( CakeRequest | array $request ) : void Takes parameter and path information back from the Dispatcher, sets these parameters as the current request parameters that are merged with URL arrays created later in the request.
stripPlugin ( string $base, string $plugin = null ) : string Removes the plugin name from the base URL.
url ( string | array $url = null, boolean | array $full = false ) : string Finds URL for specified action.

보호된 메소드들

메소드 설명
_handleNoRoute ( array $url ) : string A special fallback method that handles URL arrays that cannot match any defined routes.
_loadRoutes ( ) : void Loads route configuration
_parseExtension ( string $url ) : array Parses a file extension out of a URL, if Router::parseExtensions() is enabled.
_setPrefixes ( ) : void Sets the Routing prefixes.
_validateRouteClass ( string $routeClass ) : string Validates that the passed route class exists and is a subclass of CakeRoute

메소드 상세

_handleNoRoute() 보호된 정적인 메소드

A special fallback method that handles URL arrays that cannot match any defined routes.
또한 보기: Router::url()
protected static _handleNoRoute ( array $url ) : string
$url array A URL that didn't match any routes
리턴 string A generated URL for the array

_loadRoutes() 보호된 정적인 메소드

Loads route configuration
protected static _loadRoutes ( ) : void
리턴 void

_parseExtension() 보호된 정적인 메소드

Parses a file extension out of a URL, if Router::parseExtensions() is enabled.
protected static _parseExtension ( string $url ) : array
$url string URL.
리턴 array Returns an array containing the altered URL and the parsed extension.

_setPrefixes() 보호된 정적인 메소드

Sets the Routing prefixes.
protected static _setPrefixes ( ) : void
리턴 void

_validateRouteClass() 보호된 정적인 메소드

Validates that the passed route class exists and is a subclass of CakeRoute
protected static _validateRouteClass ( string $routeClass ) : string
$routeClass string Route class name
리턴 string

connect() 공개 정적인 메소드

Routes are a way of connecting request URLs to objects in your application. At their core routes are a set of regular expressions that are used to match requests to destinations. Examples: Router::connect('/:controller/:action/*'); The first token ':controller' will be used as a controller name while the second is used as the action name. the '/*' syntax makes this route greedy in that it will match requests like /posts/index as well as requests like /posts/edit/1/foo/bar. Router::connect('/home-page', array('controller' => 'pages', 'action' => 'display', 'home')); The above shows the use of route parameter defaults, and providing routing parameters for a static route. Router::connect( '/:lang/:controller/:action/:id', array(), array('id' => '[0-9]+', 'lang' => '[a-z]{3}') ); Shows connecting a route with custom route parameters as well as providing patterns for those parameters. Patterns for routing parameters do not need capturing groups, as one will be added for each route params. $defaults is merged with the results of parsing the request URL to form the final routing destination and its parameters. This destination is expressed as an associative array by Router. See the output of {@link parse()}. $options offers four 'special' keys. pass, named, persist and routeClass have special meaning in the $options array. - pass is used to define which of the routed parameters should be shifted into the pass array. Adding a parameter to pass will remove it from the regular route array. Ex. 'pass' => array('slug') - persist is used to define which route parameters should be automatically included when generating new URLs. You can override persistent parameters by redefining them in a URL or remove them by setting the parameter to false. Ex. 'persist' => array('lang') - routeClass is used to extend and change how individual routes parse requests and handle reverse routing, via a custom routing class. Ex. 'routeClass' => 'SlugRoute' - named is used to configure named parameters at the route level. This key uses the same options as Router::connectNamed() You can also add additional conditions for matching routes to the $defaults array. The following conditions can be used: - [type] Only match requests for specific content types. - [method] Only match requests with specific HTTP verbs. - [server] Only match when $_SERVER['SERVER_NAME'] matches the given value. Example of using the [method] condition: Router::connect('/tasks', array('controller' => 'tasks', 'action' => 'index', '[method]' => 'GET')); The above route will only be matched for GET requests. POST requests will fail to match this route.
또한 보기: routes
public static connect ( string $route, array $defaults = [], array $options = [] ) : array
$route string A string describing the template of the route
$defaults array An array describing the default route parameters. These parameters will be used by default and can supply routing parameters that are not dynamic. See above.
$options array An array matching the named elements in the route to regular expressions which that element should match. Also contains additional parameters such as which routed parameters should be shifted into the passed arguments, supplying patterns for routing parameters and supplying the name of a custom routing class.
리턴 array Array of routes

connectNamed() 공개 정적인 메소드

Do not parse any named parameters: Router::connectNamed(false); Parse only default parameters used for CakePHP's pagination: Router::connectNamed(false, array('default' => true)); Parse only the page parameter if its value is a number: Router::connectNamed(array('page' => '[\d]+'), array('default' => false, 'greedy' => false)); Parse only the page parameter no matter what. Router::connectNamed(array('page'), array('default' => false, 'greedy' => false)); Parse only the page parameter if the current action is 'index'. Router::connectNamed( array('page' => array('action' => 'index')), array('default' => false, 'greedy' => false) ); Parse only the page parameter if the current action is 'index' and the controller is 'pages'. Router::connectNamed( array('page' => array('action' => 'index', 'controller' => 'pages')), array('default' => false, 'greedy' => false) ); ### Options - greedy Setting this to true will make Router parse all named params. Setting it to false will parse only the connected named params. - default Set this to true to merge in the default set of named parameters. - reset Set to true to clear existing rules and start fresh. - separator Change the string used to separate the key & value in a named parameter. Defaults to :
public static connectNamed ( array $named, array $options = [] ) : array
$named array A list of named parameters. Key value pairs are accepted where values are either regex strings to match, or arrays as seen above.
$options array Allows to control all settings: separator, greedy, reset, default
리턴 array

currentRoute() 공개 정적인 메소드

Returns the route matching the current request (useful for requestAction traces)
public static currentRoute ( ) : CakeRoute
리턴 CakeRoute Matching route object.

defaultRouteClass() 공개 정적인 메소드

Set the default route class to use or return the current one
public static defaultRouteClass ( string $routeClass = null ) : string | null
$routeClass string The route class to set as default.
리턴 string | null The default route class.

extensions() 공개 정적인 메소드

To initially set extensions use Router::parseExtensions() To add more see setExtensions()
public static extensions ( ) : array
리턴 array Array of extensions Router is configured to parse.

fullBaseUrl() 공개 정적인 메소드

## Note: If you change the configuration value App.fullBaseUrl during runtime and expect the router to produce links using the new setting, you are required to call this method passing such value again.
public static fullBaseUrl ( string $base = null ) : string
$base string the prefix for URLs generated containing the domain. For example: ``http://example.com``
리턴 string

getNamedExpressions() 공개 정적인 메소드

Gets the named route elements for use in app/Config/routes.php
또한 보기: Router::$_namedExpressions
public static getNamedExpressions ( ) : array
리턴 array Named route elements

getParam() 공개 정적인 메소드

Gets URL parameter by name
public static getParam ( string $name = 'controller', boolean $current = false ) : string | null
$name string Parameter name
$current boolean Current parameter, useful when using requestAction
리턴 string | null Parameter value

getParams() 공개 정적인 메소드

Gets parameter information
public static getParams ( boolean $current = false ) : array
$current boolean Get current request parameter, useful when using requestAction
리턴 array Parameter information

getPaths() 공개 정적인 메소드

Gets path information
public static getPaths ( boolean $current = false ) : array
$current boolean Current parameter, useful when using requestAction
리턴 array

getRequest() 공개 정적인 메소드

Gets the current request object, or the first one.
public static getRequest ( boolean $current = false ) : CakeRequest | null
$current boolean True to get the current request object, or false to get the first one.
리턴 CakeRequest | null Null if stack is empty.

mapResources() 공개 정적인 메소드

### Options: - 'id' - The regular expression fragment to use when matching IDs. By default, matches integer values and UUIDs. - 'prefix' - URL prefix to use for the generated routes. Defaults to '/'.
public static mapResources ( string | array $controller, array $options = [] ) : array
$controller string | array A controller name or array of controller names (i.e. "Posts" or "ListItems")
$options array Options to use when generating REST routes
리턴 array Array of mapped resources

namedConfig() 공개 정적인 메소드

Gets the current named parameter configuration values.
또한 보기: Router::$_namedConfig
public static namedConfig ( ) : array
리턴 array

normalize() 공개 정적인 메소드

Will strip the base path off and replace any double /'s. It will not unify the casing and underscoring of the input value.
public static normalize ( array | string $url = '/' ) : string
$url array | string URL to normalize Either an array or a string URL.
리턴 string Normalized URL

parse() 공개 정적인 메소드

Parses given URL string. Returns 'routing' parameters for that URL.
public static parse ( string $url ) : array
$url string URL to be parsed
리턴 array Parsed elements from URL

parseExtensions() 공개 정적인 메소드

For example, http://example.com/posts.rss would yield a file extension of "rss". The file extension itself is made available in the controller as $this->params['ext'], and is used by the RequestHandler component to automatically switch to alternate layouts and templates, and load helpers corresponding to the given content, i.e. RssHelper. Switching layouts and helpers requires that the chosen extension has a defined mime type in CakeResponse A list of valid extension can be passed to this method, i.e. Router::parseExtensions('rss', 'xml'); If no parameters are given, anything after the first . (dot) after the last / in the URL will be parsed, excluding querystring parameters (i.e. ?q=...).
또한 보기: RequestHandler::startup()
public static parseExtensions ( ) : void
리턴 void

popRequest() 공개 정적인 메소드

Pops a request off of the request stack. Used when doing requestAction
또한 보기: Router::setRequestInfo()
또한 보기: Object::requestAction()
public static popRequest ( ) : CakeRequest
리턴 CakeRequest The request removed from the stack.

prefixes() 공개 정적인 메소드

Returns the list of prefixes used in connected routes
public static prefixes ( ) : array
리턴 array A list of prefixes used in connected routes

promote() 공개 정적인 메소드

Promote a route (by default, the last one added) to the beginning of the list
public static promote ( integer $which = null ) : boolean
$which integer A zero-based array index representing the route to move. For example, if 3 routes have been added, the last route would be 2.
리턴 boolean Returns false if no route exists at the position specified by $which.

queryString() 공개 정적인 메소드

Generates a well-formed querystring from $q
public static queryString ( string | array $q, array $extra = [], boolean $escape = false ) : array
$q string | array Query string Either a string of already compiled query string arguments or an array of arguments to convert into a query string.
$extra array Extra querystring parameters.
$escape boolean Whether or not to use escaped &
리턴 array

redirect() 공개 정적인 메소드

Redirection routes are different from normal routes as they perform an actual header redirection if a match is found. The redirection can occur within your application or redirect to an outside location. Examples: Router::redirect('/home/*', array('controller' => 'posts', 'action' => 'view'), array('persist' => true)); Redirects /home/* to /posts/view and passes the parameters to /posts/view. Using an array as the redirect destination allows you to use other routes to define where a URL string should be redirected to. Router::redirect('/posts/*', 'http://google.com', array('status' => 302)); Redirects /posts/* to http://google.com with a HTTP status of 302 ### Options: - status Sets the HTTP status (default 301) - persist Passes the params to the redirected route, if it can. This is useful with greedy routes, routes that end in * are greedy. As you can remap URLs and not loose any passed/named args.
또한 보기: routes
public static redirect ( string $route, array $url, array $options = [] ) : array
$route string A string describing the template of the route
$url array A URL to redirect to. Can be a string or a CakePHP array-based URL
$options array An array matching the named elements in the route to regular expressions which that element should match. Also contains additional parameters such as which routed parameters should be shifted into the passed arguments. As well as supplying patterns for routing parameters.
리턴 array Array of routes

reload() 공개 정적인 메소드

Reloads default Router settings. Resets all class variables and removes all connected routes.
public static reload ( ) : void
리턴 void

requestRoute() 공개 정적인 메소드

Returns the route matching the current request URL.
public static requestRoute ( ) : CakeRoute
리턴 CakeRoute Matching route object.

resourceMap() 공개 정적인 메소드

Resource map getter & setter.
또한 보기: Router::$_resourceMap
public static resourceMap ( array $resourceMap = null ) : mixed
$resourceMap array Resource map
리턴 mixed

reverse() 공개 정적인 메소드

Works similarly to Router::url(), but since parsed URL's contain additional 'pass' and 'named' as well as 'url.url' keys. Those keys need to be specially handled in order to reverse a params array into a string URL. This will strip out 'autoRender', 'bare', 'requested', and 'return' param names as those are used for CakePHP internals and should not normally be part of an output URL.
public static reverse ( CakeRequest | array $params, boolean $full = false ) : string
$params CakeRequest | array The params array or CakeRequest object that needs to be reversed.
$full boolean Set to true to include the full URL including the protocol when reversing the URL.
리턴 string The string that is the reversed result of the array

setExtensions() 공개 정적인 메소드

To have the extensions parsed you still need to call Router::parseExtensions()
public static setExtensions ( array $extensions, boolean $merge = true ) : array
$extensions array List of extensions to be added as valid extension
$merge boolean Default true will merge extensions. Set to false to override current extensions
리턴 array

setRequestInfo() 공개 정적인 메소드

Nested requests will create a stack of requests. You can remove requests using Router::popRequest(). This is done automatically when using Object::requestAction(). Will accept either a CakeRequest object or an array of arrays. Support for accepting arrays may be removed in the future.
public static setRequestInfo ( CakeRequest | array $request ) : void
$request CakeRequest | array Parameters and path information or a CakeRequest object.
리턴 void

stripPlugin() 공개 정적인 메소드

Removes the plugin name from the base URL.
public static stripPlugin ( string $base, string $plugin = null ) : string
$base string Base URL
$plugin string Plugin name
리턴 string base URL with plugin name removed if present

url() 공개 정적인 메소드

Returns a URL pointing to a combination of controller and action. Param $url can be: - Empty - the method will find address to actual controller/action. - '/' - the method will find base URL of application. - A combination of controller/action - the method will find URL for it. There are a few 'special' parameters that can change the final URL string that is generated - base - Set to false to remove the base path from the generated URL. If your application is not in the root directory, this can be used to generate URLs that are 'cake relative'. cake relative URLs are required when using requestAction. - ? - Takes an array of query string parameters - # - Allows you to set URL hash fragments. - full_base - If true the Router::fullBaseUrl() value will be prepended to generated URLs.
public static url ( string | array $url = null, boolean | array $full = false ) : string
$url string | array Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4" or an array specifying any of the following: 'controller', 'action', and/or 'plugin', in addition to named arguments (keyed array elements), and standard URL arguments (indexed array elements)
$full boolean | array If (bool) true, the full base URL will be prepended to the result. If an array accepts the following keys - escape - used when making URLs embedded in html escapes query string '&' - full - if true the full base URL will be prepended.
리턴 string Full translated URL with base path.

프로퍼티 상세

$_currentRoute 보호되어 있는 정적으로 프로퍼티

The route matching the URL of the current request
protected static array $_currentRoute
리턴 array

$_fullBaseUrl 보호되어 있는 정적으로 프로퍼티

Contains the base string that will be applied to all generated URLs For example https://example.com
protected static string $_fullBaseUrl
리턴 string

$_initialState 보호되어 있는 정적으로 프로퍼티

Initial state is populated the first time reload() is called which is at the bottom of this file. This is a cheat as get_class_vars() returns the value of static vars even if they have changed.
protected static array $_initialState
리턴 array

$_namedConfig 보호되어 있는 정적으로 프로퍼티

Stores all information necessary to decide what named arguments are parsed under what conditions.
protected static string $_namedConfig
리턴 string

$_namedExpressions 보호되어 있는 정적으로 프로퍼티

Named expressions
protected static array $_namedExpressions
리턴 array

$_parseExtensions 보호되어 있는 정적으로 프로퍼티

Directive for Router to parse out file extensions for mapping to Content-types.
protected static bool $_parseExtensions
리턴 boolean

$_prefixes 보호되어 있는 정적으로 프로퍼티

Includes admin prefix
protected static array $_prefixes
리턴 array

$_requests 보호되어 있는 정적으로 프로퍼티

This will contain more than one request object when requestAction is used.
protected static array $_requests
리턴 array

$_resourceMap 보호되어 있는 정적으로 프로퍼티

Default HTTP request method => controller action map.
protected static array $_resourceMap
리턴 array

$_resourceMapped 보호되어 있는 정적으로 프로퍼티

List of resource-mapped controllers
protected static array $_resourceMapped
리턴 array

$_routeClass 보호되어 있는 정적으로 프로퍼티

Default route class to use
protected static string $_routeClass
리턴 string

$_validExtensions 보호되어 있는 정적으로 프로퍼티

List of valid extensions to parse from a URL. If null, any extension is allowed.
protected static array $_validExtensions
리턴 array

$initialized 공개적으로 정적으로 프로퍼티

Have routes been loaded
public static bool $initialized
리턴 boolean

$routes 공개적으로 정적으로 프로퍼티

Array of routes connected with Router::connect()
public static array $routes
리턴 array