Yaf_Route_Map::__construct

(Yaf >=1.0.0)

Yaf_Route_Map::__constructConstruct a map route

Description

publicfunction Yaf_Route_Map::__construct(bool $controller_prefer = false, string $delimiter = '')

Construct a map route. A map route maps the whole URI to a controller name or an action name.

Parameters

controller_prefer

Whether to map the URI to a controller name. If false, the URI is mapped to an action name.

delimiter

The delimiter used to separate the mapped name from the request parameters in the URI. If it occurs as a path segment preceded by a slash, everything after it is parsed as request parameters instead of being part of the mapped name. If empty, no such splitting happens during routing.

Return Values

No value is returned.

Examples

Example #1 Yaf_Route_Map example

<?php
/**
 * Add a map route to the Yaf_Router route stack
 */
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
    new Yaf_Route_Map());
?>

The above example will output something similar to:

/* for http://yourdomain.com/product/foo/bar
 * the request will carry the following values:
 */
array(
  "action" => "product_foo_bar",
)

Example #2 Yaf_Route_Map example

<?php
/**
 * Add a map route with a delimiter to the Yaf_Router route stack
 */
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
    new Yaf_Route_Map(true, "_"));
?>

The above example will output something similar to:

/* for http://yourdomain.com/user/list/_/foo/22
 * the request will carry the following values:
 */
array(
    "controller" => "User_List",
)

/**
 * and request parameters:
 */
array(
  "foo" => "22",
)

Example #3 Yaf_Route_Map example

<?php
/**
 * Add a map route to the route stack by calling addConfig
 */
$config = array(
    "name" => array(
       "type"             => "map", // Yaf_Route_Map route
       "controllerPrefer" => FALSE,
       "delimiter"        => "#!",
    ),
);
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
    new Yaf_Config_Simple($config));
?>

See Also

add a note

User Contributed Notes

There are no user contributed notes for this page.