CakeFest 2024: The Official CakePHP Conference

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() の例

<?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);
}
}
?>
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top