Php/docs/yaf-router.addroute

提供:Dev Guides
< Php
移動先:案内検索

Yaf_Router::addRoute

(Yaf >=1.0.0)

Yaf_Router::addRoute新しいルートをルーターに追加する


説明

public Yaf_Router::addRoute ( string $name , Yaf_Route_Abstract $route ) : bool

Yaf_Router はデフォルトのルートとして Yaf_Route_Static を使います。ルーターのルートスタックにそれ以外のルートを追加するときに、このメソッドを使います。

ルートスタックに後から追加したルートのほうが先に呼ばれます。 どれかひとつのルーターが true を返せば、そこでルーティングが終わります。それ以外の場合は 次のルーターを呼びます。


パラメータ

この関数にはパラメータはありません。


返り値

例1 Yaf_Dispatcher::autoRender() の例

<?phpclass Bootstrap extends Yaf_Bootstrap_Abstract{    public function _initConfig() {        $config = Yaf_Application::app()->getConfig();        Yaf_Registry::set("config", $config);    }    public function _initRoute(Yaf_Dispatcher $dispatcher) {        $router = $dispatcher->getRouter();        /**         * we can add some pre-defined routes in application.ini         */        $router->addConfig(Yaf_Registry::get("config")->routes);        /**         * add a Rewrite route, then for a request uri:          * http://***/product/list/22/foo         * will be matched by this route, and result:         *         *  [module] =>          *  [controller] => product         *  [action] => info         *  [method] => GET         *  [params:protected] => Array         *      (         *          [id] => 22         *          [name] => foo         *      )         *          */        $route  = new Yaf_Route_Rewrite(            "/product/list/:id/:name",            array(                "controller" => "product",                "action"     => "info",            )        );                 $router->addRoute('dummy', $route);    }?>