Router Class Reference

Inheritance diagram for Router:

Object List of all members.

Public Member Functions

 __connectDefaultRoutes ()
 __mapRoute ($route, $params=array())
 __matchRoute ($route, $url)
 __parseExtension ($url)
 compile ($i)
 matchNamed ($param, $val, $rule, $context=array())
 normalize ($url= '/')

Static Public Member Functions

 connect ($route, $default=array(), $params=array())
 connectNamed ($named, $options=array())
 currentRoute ()
 getArgs ($args, $options=array())
getInstance ()
 getNamedElements ($params, $controller=null, $action=null)
 getNamedExpressions ()
 getParam ($name= 'controller', $current=false)
 getParams ($current=false)
 getPaths ($current=false)
 mapResources ($controller, $options=array())
 mapRouteElements ($route, $url)
 parse ($url)
 parseExtensions ()
 prefixes ()
 promote ($which=null)
 queryString ($q, $extra=array(), $escape=false)
 reload ()
 requestRoute ()
 setRequestInfo ($params)
 stripEscape ($param)
 stripPlugin ($base, $plugin=null)
 url ($url=null, $full=false)
 writeRoute ($route, $default, $params)

Public Attributes

 $__admin = null
 $__currentRoute = array()
 $__defaultsMapped = false
 $__headerMap
 $__named
 $__params = array()
 $__parseExtensions = false
 $__paths = array()
 $__prefixes = array()
 $__resourceMap
 $__resourceMapped = array()
 $__validExtensions = null
 $named
 $routes = array()

Detailed Description

Definition at line 40 of file router.php.


Member Function Documentation

Router::__connectDefaultRoutes (  ) 

Connects the default, built-in routes, including admin routes, and (deprecated) web services routes.

Returns:
void private

Definition at line 582 of file router.php.

References connect(), Configure::listObjects(), and underscore().

Router::__mapRoute ( route,
params = array() 
)

Merges URL parameters into a route string

Parameters:
array $route Route
array $params Parameters
Returns:
string Merged URL with parameters private

Definition at line 1044 of file router.php.

Router::__matchRoute ( route,
url 
)

Checks to see if the given URL matches the given route

Parameters:
array $route
string $url
Returns:
mixed Boolean false on failure, otherwise array private

Definition at line 495 of file router.php.

References $url, and env().

Referenced by parse().

Router::__parseExtension ( url  ) 

Parses a file extension out of a URL, if Router::parseExtensions() is enabled.

Parameters:
string $url
Returns:
array Returns an array containing the altered URL and the parsed extension. private

Definition at line 551 of file router.php.

References $url, a(), ext(), and url().

Referenced by parse().

Router::compile ( i  ) 

Compiles a route by numeric key and returns the compiled expression, replacing the existing uncompiled route. Do not call statically.

Parameters:
integer $i
Returns:
array Returns an array containing the compiled route public

Definition at line 533 of file router.php.

References writeRoute().

Router::connect ( route,
default = array(),
params = array() 
) [static]

Returns this object's routes array. Returns false if there are no routes available.

Parameters:
string $route An empty string, or a route string "/"
array $default NULL or an array describing the default route
array $params An array matching the named elements in the route to regular expressions which that element should match.
See also:
routes
Returns:
array Array of routes public

Definition at line 201 of file router.php.

References getInstance().

Referenced by __connectDefaultRoutes(), and mapResources().

Router::connectNamed ( named,
options = array() 
) [static]

Specifies what named parameters CakePHP should be parsing. The most common setups are:

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' => '[]+'), array('default' => false, 'greedy' => false)); }}}

Parse only the page parameter no mater 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)); }}}

Parameters:
array $named A list of named parameters. Key value pairs are accepted where values are either regex strings to match, or arrays as seen above.
array $options Allows to control all settings: separator, greedy, reset, default
Returns:
array public

Definition at line 244 of file router.php.

References getInstance().

Router::currentRoute (  )  [static]

Returns the route matching the current request (useful for requestAction traces)

Returns:
array Matching route public

Definition at line 1230 of file router.php.

Router::getArgs ( args,
options = array() 
) [static]

Takes an passed params and converts it to args

Parameters:
array $params
Returns:
array Array containing passed and named parameters public

Definition at line 1316 of file router.php.

Referenced by Dispatcher::_restructureParams(), and parse().

& Router::getInstance (  )  [static]

Gets a reference to the Router object instance

Returns:
object Object instance public

Definition at line 169 of file router.php.

References Configure::read().

Referenced by ConsoleShell::__loadRoutes(), connect(), connectNamed(), getNamedExpressions(), ConsoleShell::main(), mapResources(), parse(), and prefixes().

Router::getNamedElements ( params,
controller = null,
action = null 
) [static]

Takes an array of URL parameters and separates the ones that can be used as named arguments

Parameters:
array $params Associative array of URL parameters.
string $controller Name of controller being routed. Used in scoping.
string $action Name of action being routed. Used in scoping.
Returns:
array public

Definition at line 1102 of file router.php.

Router::getNamedExpressions (  )  [static]

Gets the named route elements for use in app/config/routes.php

Returns:
array Named route elements public
See also:
Router::$__named

Definition at line 186 of file router.php.

References getInstance().

Referenced by Dispatcher::parseParams().

Router::getParam ( name = 'controller',
current = false 
) [static]

Gets URL parameter by name

Parameters:
string $name Parameter name
boolean $current Current parameter
Returns:
string Parameter value public

Definition at line 667 of file router.php.

Router::getParams ( current = false  )  [static]

Gets parameter information

Parameters:
boolean $current Get current parameter (true)
Returns:
array Parameter information public

Definition at line 648 of file router.php.

Referenced by CakeErrorController::__construct().

Router::getPaths ( current = false  )  [static]

Gets path information

Parameters:
boolean $current Current parameter
Returns:
array public

Definition at line 682 of file router.php.

Referenced by CakeErrorController::__construct().

Router::mapResources ( controller,
options = array() 
) [static]

Creates REST resource routes for the given controller(s)

Options:

Parameters:
mixed $controller A controller name or array of controller names (i.e. "Posts" or "ListItems")
array $options Options to use when generating REST routes
Returns:
void public

Definition at line 291 of file router.php.

References $id, $url, connect(), getInstance(), and underscore().

Router::mapRouteElements ( route,
url 
) [static]

Maps a URL array onto a route and returns the string result, or false if no match

Parameters:
array $route Route Route
array $url URL URL to map
Returns:
mixed Result (as string) or false if no match public

Definition at line 941 of file router.php.

Router::matchNamed ( param,
val,
rule,
context = array() 
)

Return true if a given named $param's $val matches a given $rule depending on $context. Currently implemented rule types are controller, action and match that can be combined with each other.

Parameters:
string $param The name of the named parameter
string $val The value of the named parameter
array $rule The rule(s) to apply, can also be a match string
string $context An array with additional context information (controller / action)
Returns:
boolean public

Definition at line 1128 of file router.php.

Router::normalize ( url = '/'  ) 

Normalizes a URL for purposes of comparison

Parameters:
mixed $url URL to normalize
Returns:
string Normalized URL public

Definition at line 1189 of file router.php.

Referenced by AuthComponent::__setDefaults(), ErrorHandler::error404(), AuthComponent::logout(), AuthComponent::redirect(), and AuthComponent::startup().

Router::parse ( url  )  [static]

Parses given URL and returns an array of controllers, action and parameters taken from that URL.

Parameters:
string $url URL to be parsed
Returns:
array Parsed elements from URL public

Definition at line 403 of file router.php.

References $out, $url, __matchRoute(), __parseExtension(), a(), ext(), getArgs(), getInstance(), stripslashes_deep(), and url().

Referenced by ConsoleShell::main(), and Dispatcher::parseParams().

Router::parseExtensions (  )  [static]

Instructs the router to parse out file extensions from the URL. For example, http://example.com/posts.rss would yield an file extension of "rss". The file extension itself is made available in the controller as $this->params['url']['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.

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

public

Returns:
void

Definition at line 1301 of file router.php.

Router::prefixes (  )  [static]

Returns the list of prefixes used in connected routes

Returns:
array A list of prefixes used in connected routes public

Definition at line 390 of file router.php.

References getInstance().

Referenced by Dispatcher::dispatch().

Router::promote ( which = null  )  [static]

Promote a route (by default, the last one added) to the beginning of the list

Parameters:
$which A zero-based array index representing the route to move. For example, if 3 routes have been added, the last route would be 2.
Returns:
boolean Retuns false if no route exists at the position specified by $which. public

Definition at line 715 of file router.php.

Router::queryString ( q,
extra = array(),
escape = false 
) [static]

Generates a well-formed querystring from $q

Parameters:
mixed $q Query string
array $extra Extra querystring parameters.
bool $escape Whether or not to use escaped &
Returns:
array public

Definition at line 1160 of file router.php.

Referenced by AuthComponent::startup().

Router::reload (  )  [static]

Reloads default Router settings

public

Returns:
void

Definition at line 699 of file router.php.

Router::requestRoute (  )  [static]

Returns the route matching the current request URL.

Returns:
array Matching route public

Definition at line 1219 of file router.php.

Router::setRequestInfo ( params  )  [static]

Takes parameter and path information back from the Dispatcher

Parameters:
array $params Parameters and path information
Returns:
void public

Definition at line 625 of file router.php.

Referenced by CacheHelper::__writeFile(), and Dispatcher::dispatch().

Router::stripEscape ( param  )  [static]

Strip escape characters from parameter values.

Parameters:
mixed $param Either an array, or a string
Returns:
mixed Array or string escaped public

Definition at line 1264 of file router.php.

Referenced by Dispatcher::parseParams().

Router::stripPlugin ( base,
plugin = null 
) [static]

Removes the plugin name from the base URL.

Parameters:
string $base Base URL
string $plugin Plugin name
Returns:
base url with plugin name removed if present public

Definition at line 1243 of file router.php.

Router::url ( url = null,
full = false 
) [static]

Finds URL for specified action.

Returns an URL pointing to a combination of controller and action. Param $url can be:

Parameters:
mixed $url 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)
mixed $full 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.
Returns:
string Full translated URL with base path. public

Definition at line 750 of file router.php.

Referenced by Dispatcher::__extractParams(), __parseExtension(), Controller::flash(), JsHelper::load_(), parse(), Controller::redirect(), Helper::url(), and View::uuid().

Router::writeRoute ( route,
default,
params 
) [static]

Builds a route regular expression

Parameters:
string $route An empty string, or a route string "/"
array $default NULL or an array describing the default route
array $params An array matching the named elements in the route to regular expressions which that element should match.
Returns:
array
See also:
routes public

Definition at line 322 of file router.php.

References a().

Referenced by compile().


Member Data Documentation

Router::$__admin = null

Definition at line 54 of file router.php.

Router::$__currentRoute = array()

Definition at line 108 of file router.php.

Router::$__defaultsMapped = false

Definition at line 161 of file router.php.

Router::$__headerMap

Initial value:

 array(
        'type'      => 'content_type',
        'method'    => 'request_method',
        'server'    => 'server_name'
    )

Definition at line 115 of file router.php.

Router::$__named

Initial value:

 array(
        'Action'    => 'index|show|add|create|edit|update|remove|del|delete|view|item',
        'Year'      => '[12][0-9]{3}',
        'Month'     => '0[1-9]|1[012]',
        'Day'       => '0[1-9]|[12][0-9]|3[01]',
        'ID'        => '[0-9]+',
        'UUID'      => '[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}'
    )

Definition at line 82 of file router.php.

Router::$__params = array()

Definition at line 147 of file router.php.

Router::$__parseExtensions = false

Definition at line 68 of file router.php.

Router::$__paths = array()

Definition at line 154 of file router.php.

Router::$__prefixes = array()

Definition at line 61 of file router.php.

Router::$__resourceMap

Initial value:

 array(
        array('action' => 'index',  'method' => 'GET',      'id' => false),
        array('action' => 'view',   'method' => 'GET',      'id' => true),
        array('action' => 'add',    'method' => 'POST',     'id' => false),
        array('action' => 'edit',   'method' => 'PUT',      'id' => true),
        array('action' => 'delete', 'method' => 'DELETE',   'id' => true),
        array('action' => 'edit',   'method' => 'POST',     'id' => true)
    )

Definition at line 126 of file router.php.

Router::$__resourceMapped = array()

Definition at line 140 of file router.php.

Router::$__validExtensions = null

Definition at line 75 of file router.php.

Router::$named

Initial value:

 array(
        'default' => array('page', 'fields', 'order', 'limit', 'recursive', 'sort', 'direction', 'step'),
        'greedy' => true,
        'separator' => ':',
        'rules' => false,
    )

Definition at line 96 of file router.php.

Router::$routes = array()

Definition at line 47 of file router.php.


The documentation for this class was generated from the following file:
Generated on Sun Nov 22 00:30:56 2009 for CakePHP 1.2.x.x (v1.2.4.8284) by doxygen 1.4.7