Yet Another Framework Yaf_Router::getCurrentRoute

(Yaf >=1.0.0)

Yaf_Router::getCurrentRoute — 유효 경로 이름 가져오기


설명

public Yaf_Router::getCurrentRoute(): string

경로 프로세스에서 유효한 경로의 이름을 가져옵니다.

메모: 라우트 프로세스가 완료된 후에 이 메서드를 호출해야 합니다. 그 전에는 이 메서드가 항상 null을 반환하기 때문입니다.


매개변수

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


반환 값

문자열, 유효 경로의 이름입니다.


Examples

예제 #1 부트스트랩에 일부 경로 등록

                  
<?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();
        $rewrite_route  = new Yaf_Route_Rewrite(
            "/product/list/:page",
            array(
                "controller" => "product",
                "action"     => "list",
            )
        );

        $regex_route  = new Yaf_Route_Rewrite(
            "#^/product/info/(\d+)",
            array(
                "controller" => "product",
                "action"     => "info",
            )
        );

        $router->addRoute('rewrite', $rewrite_route)->addRoute('regex', $regex_route);
    }

    /**
     * register plugin
     */
    public function __initPlugins(Yaf_Dispatcher $dispatcher) {
        $dispatcher->registerPlugin(new DummyPlugin());
    }
}
?>
                  
                

예제 #2 플러그인 Dummy.php(application.directory/plugins 아래)

                  
<?php
class DummyPlugin extends Yaf_Plugin_Abstract {
    public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
         var_dump(Yaf_Dispatcher::getInstance()->getRouter()->getCurrentRoute());
    }
}
?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

/* for http://yourdomain.com/product/list/1
 * DummyPlugin will output:
 */
string(7) "rewrite"

/* for http://yourdomain.com/product/info/34
 * DummyPlugin will output:
 */
string(5) "regex"

/* for other request URI
 * DummyPlugin will output:
 */
string(8) "_default"
                

기타