Router Class Reference

Inheritance diagram for Router:

Object

List of all members.


Public Member Functions

 matchNamed ($param, $val, $rule, $context=array())
 matchRoute ($route, $url)
 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())
 reload ()
 requestRoute ()
 setRequestInfo ($params)
 stripEscape ($param)
 stripPlugin ($base, $plugin)
 url ($url=null, $full=false)
 writeRoute ($route, $default, $params)

Public Attributes

 $named
 $routes = array()

Detailed Description

Definition at line 43 of file router.php.


Member Function Documentation

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 203 of file router.php.

References getInstance(), Configure::read(), and writeRoute().

Referenced by 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 public

Definition at line 248 of file router.php.

References $named, and getInstance().

Router::currentRoute (  )  [static]

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

Returns:
array Matching route public

Definition at line 1190 of file router.php.

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

Takes an passed params and converts it to args

public

Parameters:
array $params

Definition at line 1275 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 172 of file router.php.

Referenced by connect(), connectNamed(), getNamedExpressions(), ConsoleShell::main(), mapResources(), matchRoute(), 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 1069 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 188 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 649 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 630 of file router.php.

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

Gets path information

Parameters:
boolean $current Current parameter
Returns:
array public

Definition at line 665 of file router.php.

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

Creates REST resource routes for the given controller(s)

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 '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

Definition at line 291 of file router.php.

References connect(), getInstance(), ife(), and Inflector::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 907 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 1095 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 public

Definition at line 493 of file router.php.

References $url, env(), and getInstance().

Referenced by parse().

Router::normalize ( url = '/'  ) 

Normalizes a URL for purposes of comparison

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

Definition at line 1151 of file router.php.

Referenced by 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 404 of file router.php.

References $named, $out, $url, a(), getArgs(), getInstance(), matchRoute(), 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

Definition at line 1261 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 391 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 696 of file router.php.

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

Generates a well-formed querystring from $q

Parameters:
mixed $q Query string
array $extra Extra querystring parameters
Returns:
array public

Definition at line 1126 of file router.php.

Router::reload (  )  [static]

Reloads default Router settings

public

Definition at line 681 of file router.php.

Router::requestRoute (  )  [static]

Returns the route matching the current request URL.

Returns:
array Matching route public

Definition at line 1179 of file router.php.

Router::setRequestInfo ( params  )  [static]

Takes parameter and path information back from the Dispatcher

Parameters:
array $params Parameters and path information public

Definition at line 607 of file router.php.

Referenced by 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 1225 of file router.php.

Referenced by Dispatcher::parseParams().

Router::stripPlugin ( base,
plugin 
) [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 1203 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: + Empty - the method will find adress to actuall controller/action. + '/' - the method will find base URL of application. + A combination of controller/action - the method will find url for it.

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)
boolean $full If true, the full base URL will be prepended to the result
Returns:
string Full translated URL with base path. public

Definition at line 727 of file router.php.

Referenced by 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:
string
See also:
routes public

Definition at line 323 of file router.php.

References $pos, and a().

Referenced by connect().


Member Data Documentation

Router::$named

Initial value:

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

Definition at line 99 of file router.php.

Referenced by connectNamed(), and parse().

Router::$routes = array()

Definition at line 50 of file router.php.


The documentation for this class was generated from the following file: