ルーティング設定は config/Map.php で行います。configure()メソッド内で $this->route(...) を使用し、ルーティング設定を追加してください。初期状態では、"default" ルーティングだけが用意されています。
$this->route("default") // ルーティング名
->uri(":controller/:action") // http://.../コントローラ/アクションというURLにマッチ
->module("index") // 上記のURLにマッチした場合はindexモジュールとする
->defaults(array(
":controller" => "index", // コントローラは省略可能で、その場合はindexコントローラとする
":action" => "index", // アクションは省略可能で、その場合はindexアクションとする
));
例えばURLが http://.../foo/bar の場合、実行されるアクションは indexモジュール の fooコントローラ の barアクション となります。
$this->route("test") // ルーティング名
->uri("test/:action") // http://.../test/アクションというURLにマッチ
->module("test") // 上記のURLにマッチした場合はtestモジュールとする
->controller("index") // 上記のURLにマッチした場合はindexコントローラとする
->defaults(array(
":action" => "index" // アクションは省略可能で、その場合はindexアクションとする
));
したがって、実行されるアクションは testモジュール の indexコントローラ の fooアクション となります。
$this->route("default")
->uri(":controller/:action/:p1/:p2")
->module("index")
->defaults(array(
":controller" => "index",
":action" => "index",
":p1" => null,
":p2" => null,
));
URLが http://.../index/index/10/20 の場合、コントローラ(アクション)で下記のようにそれらのパラメータにアクセスすることができます。
public function myAction()
{
$p1 = $this->request->fetchParameterValue("p1");
$p2 = $this->request->fetchParameterValue("p2");
}
パラメータの形式を正規表現で拘束することもできます。
$this->route("default")
->uri(":controller/:action/:p1")
->module("index")
->requirements(array(
":p1" => "[1-9][0-9]*", // p1がある場合は[1-9][0-9]の形式である
))
->defaults(array(
":controller" => "index",
":action" => "index",
));
上記の設定では http://.../controller/action や http://.../controller/action/10 などのURLにマッチしますが、http://.../controller/action/abc や http://.../controller/action/01 にはマッチしないことになります。