Yaf_Route_Regex::route
PHP Manual
PHP Manual»Yaf_Route_Regex»Yaf_Route_Regex::route

Yaf_Route_Regex::route

(Yaf >=1.0.0)

Yaf_Route_Regex::route — Route a request

Beschreibung

public function Yaf_Route_Regex::route(Yaf_Request_Abstract $request): bool

Route the request with a regular expression: the URI is matched against the pattern given to the constructor, and the route result (the module, controller and action) is taken from the captured variables, mapped by the map parameter.

Parameter-Liste

request

The Yaf_Request_Abstract instance to route.

Rückgabewerte

Returns true if the URI matches, false otherwise, which makes the router try the next route.

Beispiele

Beispiel #1 Yaf_Route_Regex::route() example

<?php
/* assume the request URI is "/product/php-book" */
$request = new Yaf_Request_Http("/product/php-book");

$route = new Yaf_Route_Regex(
    "#^/product/([^/]+)/?$#", // match a URI leading "/product"
    array(
        'controller' => "product", // route to the product controller
    ),
    array(
        1 => "name", // $request->getParam("name") will be "php-book"
    )
);

var_dump($route->route($request));

var_dump($request->getControllerName());
var_dump($request->getParam("name"));
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

bool(true)
string(7) "product"
string(8) "php-book"

Siehe auch

To Top