PHPマニュアル/PEARマニュアル | ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot

Yaf_Router::getCurrentRoute - 使われているルート名を取得する | JavaScript入門&応用&リファレンスなら「JavaScriptist」

  

Yaf_Router::getCurrentRoute

(Yaf >=1.0.0)

Yaf_Router::getCurrentRoute使われているルート名を取得する

説明

public string Yaf_Router::getCurrentRoute ( void )

ルーティングプロセスで使われているルート名を取得します。

注意:

このメソッドはルーティングが終わってから呼ぶ必要があります。 終わる前に呼ぶと、常に NULL を返します。

パラメータ

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

返り値

ルート名を文字列で返します。

例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 $requestYaf_Response_Abstract $response) {
         
var_dump(Yaf_Dispatcher::getInstance()->getRouter()->getCurrentRoute());
    }
?>
?>

上の例の出力は、 たとえば以下のようになります。

/* http://yourdomain.com/product/list/1
 * の場合の DummyPlugin の出力
 */
string(7) "rewrite"

/* http://yourdomain.com/product/info/34
 * の場合の DummyPlugin の出力
 */
string(5) "regex"

/* その他のリクエスト URI
 * の場合の DummyPlugin の出力
 */
string(8) "_default"

参考


忘却曲線を使ってこの知識を確実に記憶に残す

フォーラムで「Yaf_Router::getCurrentRoute - 使われているルート名を取得する」について話す
各種マニュアル: PHPマニュアル | PEARマニュアル | Smarty(英語)マニュアル | PHP-GTKマニュアル | Yaf_Router::getCurrentRoute - 使われているルート名を取得する」をGoogle検索
copyright © 1997-2024 PHP ドキュメント作成グループ(ライセンス). provided by php spot. マニュアル: