Yaf_Route_Regex::__construct

(Yaf >=1.0.0)

Yaf_Route_Regex::__constructYaf_Route_Regex のコンストラクタ

説明

publicYaf_Route_Regex::__construct(
    string$match,
    array$route,
    array$map = ?,
    array$verify = ?,
    string$reverse = ?
)

パラメータ

match

正規表現のパターン。リクエストの URI とマッチさせます。 もしマッチしなければ Yaf_Route_Regexfalse を返します。

route

リクエスト URI がパターンにマッチしたときに、 Yaf_Route_Regex はこれを使ってルーティング先を判断します。

この配列で指定するモジュール、コントローラ、アクションはすべて任意指定で、 値を省略したときにはデフォルト設定を利用します。

map

マッチした結果に代入する名前の配列。

verify

reverse

URL を組み立てるときに使う文字列。 Yaf_Route_Regex::assemble() を参照ください。

注意:

このパラメータは 2.3.0 で導入されました。

戻り値

例1 Yaf_Route_Regex() の例

<?php

Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new
Yaf_Route_Regex(
"#^/product/([^/]+)/([^/])+#", //match request uri leading "/product"
array(
'controller' => "product", //route to product controller,
),
array(
1 => "name", // now you can call $request->getParam("name")
2 => "id", // to get the first captrue in the match pattern.
)
)
);
?>

例2 Yaf_Route_Regex() (2.3.0 以降) の例

<?php

Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new
Yaf_Route_Regex(
"#^/product/([^/]+)/([^/])+#i", //match request uri leading "/product"
array(
'controller' => ":name", // route to :name, which is $1 in the match result as controller name
),
array(
1 => "name", // now you can call $request->getParam("name")
2 => "id", // to get the first captrue in the match pattern.
)
)
);
?>

例3 Yaf_Route_Regex と名前付きキャプチャグループ (2.3.0 以降) の例()example

<?php

Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new
Yaf_Route_Regex(
"#^/product/(?<name>[^/]+)/([^/])+#i", //match request uri leading "/product"
array(
'controller' => ":name", // route to :name,

例4 Yaf_Route_Regex() の例

<?php

$config = array(
"name" => array(
"type" => "regex", //Yaf_Route_Regex route
"match" => "#(.*)#", //match arbitrary request uri
"route" => array(
'controller' => "product", //route to product controller,
'action' => "dummy", //route to dummy action
),
"map" => array(
1 => "uri", // now you can call $request->getParam("uri")
),
),
);
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new
Yaf_Config_Simple($config));
?>

参考

To Top