Yet Another Framework Yaf_Router::addRoute

(Yaf >=1.0.0)

Yaf_Router::addRoute — 라우터에 새 경로 추가


설명

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

기본적으로 Yaf_Route_Static을 기본 경로로 사용하는 Yaf_Router입니다. 이 메서드를 호출하여 라우터의 경로 스택에 새 경로를 추가할 수 있습니다.

새로운 경로는 이전(경로 스택)보다 먼저 호출되고 최신 라우터가 true를 반환하면 라우터 프로세스가 종료됩니다. 그렇지 않으면 더 오래된 것이 호출됩니다.


매개변수

이 함수에는 매개변수가 없습니다.


반환 값


Examples

예제 #1 Yaf_Dispatcher::autoRender() 예제

                  
<?php
class 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://example.com/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);
    }
}
?>
                  
                

기타