Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Quick StartPlugins>
^ExamplesLast updated: Mon, 26 Oct 2026

Custom Routes

Example #1 Custom routes

Besides the default Yaf_Route_Static route, custom routes can be registered on the Yaf_Router route stack, usually in a _initRoute method of the Bootstrap, using Yaf_Router::addRoute(). Routes can also be declared in configuration files and loaded with Yaf_Router::addConfig().

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

        // /user/123 -> controller=user, action=index, id=123
        $router->addRoute("user", new Yaf_Route_Rewrite(
            "/user/:id",
            array("controller" => "user", "action" => "index")
        ));
    }
}
?>

<Quick StartPlugins>
^ExamplesLast updated: Mon, 26 Oct 2026