Path

ez components / documentation / api reference / 2009.2.1 / mvctools


eZ Components 2009.2.1

MvcTools: ezcMvcRouter

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcMvcRouter

The abstract router that you need to inherit from to supply your routes. [source]

Member Variables

protected ezcMvcRequest $request
Contains the request object
protected array(ezcMvcRoute) $routes = array()
Contains all the user defined routes.

Method Summary

public ezcMvcRouter __construct( $request )
Creates a new router object
public abstract array(ezcMvcRoute) createRoutes( )
User implemented method that should provide all the routes.
public void generateUrl( $routeName, [$arguments = null] )
Generates an URL back out of a route, including possible arguments
public ezcMvcRoutingInformation getRoutingInformation( )
Returns routing information, including a controller classname from the set of routes.
public static void prefix( $prefix, $routes )
Loops over all the given routes and adds the prefix $prefix to them

Methods

__construct

ezcMvcRouter __construct( ezcMvcRequest $request )
Creates a new router object

Parameters

Name Type Description
$request ezcMvcRequest  

createRoutes

array(ezcMvcRoute) createRoutes( )
User implemented method that should provide all the routes.
It should return an array of objects that implement the ezcMvcRoute interface. This could be objects of the ezcMvcRegexpRoute class for example.

generateUrl

void generateUrl( mixed $routeName, [ $arguments = null] )
Generates an URL back out of a route, including possible arguments

Parameters

Name Type Description
$routeName mixed  
$arguments array  

getRoutingInformation

ezcMvcRoutingInformation getRoutingInformation( )
Returns routing information, including a controller classname from the set of routes.
This method is run by the dispatcher to obtain a controller. It uses the user implemented createRoutes() method from the inherited class to fetch the routes. It then loops over these routes in order - the first one that matches the request returns the routing information. The loop stops as soon as a route has matched. In case none of the routes matched with the request data an exception is thrown.

Throws

ClassDescription
ezcMvcNoRoutesException when there are no routes defined.
ezcBaseValueException when one of the returned routes was not actually an object implementing the ezcMvcRoute interface.
ezcMvcRouteNotFoundException when no routes matched the request URI.

prefix

void prefix( mixed $prefix, array(ezcMvcRoute) $routes )
Loops over all the given routes and adds the prefix $prefix to them
The methods loops over all the routes in the $routes variables and calls the prefix() method on the route with the $prefix. The $prefix should be a prefix that the route understands.

Parameters

Name Type Description
$prefix mixed  
$routes array(ezcMvcRoute)  

Throws

ClassDescription
ezcMvcRegexpRouteException if the prefix can not be prepended to one or more of the patterns in the routes.

Last updated: Tue, 23 Mar 2010