php8.5
Home/ Manual/ yaf / yaf_dispatcher/ Yaf_Dispatcher::getRouter

Yaf_Dispatcher::getRouter

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Retrieve router instance

Description

Yaf_Dispatcher::getRouter(): Yaf_Router|null

Retrieve the Yaf_Router instance used by the dispatcher to route requests.

Parameters Parameters

Return Values

The Yaf_Router instance, or null if the application is not initialized.

Examples

Yaf_Dispatcher::getRouter example

php
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
    public function _initRoute(Yaf_Dispatcher $dispatcher)
    {
        $router = $dispatcher->getRouter();

        // Route /product/42 to ProductController::detailAction
        $router->addRoute("product", new Yaf_Route_Rewrite(
            "product/:id",
            array("controller" => "product", "action" => "detail")
        ));
    }
}
?>

See Also

  • Yaf_Router

Source: reference/yaf/yaf_dispatcher/getrouter.xml · from the official PHP manual (php/doc-en)