Yet Another Framework Yaf_Route_Regex::__construct
(Yaf >=1.0.0)
Yaf_Route_Regex::__construct — Yaf_Route_Regex constructor
설명
public Yaf_Route_Regex::__construct( string $match, array $route, array $map = ?, array $verify = ?, string $reverse = ? )
매개변수
match
- 완전한 정규식 패턴은 요청 URI와 일치하는 데 사용되며 일치하지 않으면 Yaf_Route_Regex는
false
를 반환합니다. route
- 일치 패턴이 요청 uri와 일치하면 Yaf_Route_Regex는 이를 사용하여 라우팅할 m/c/a를 결정합니다.
이 배열의 m/c/a 중 하나는 optianl입니다. 특정 값을 지정하지 않으면 기본값으로 라우팅됩니다.
map
- 일치 결과에서 캡처에 이름을 할당하는 배열입니다.
verify
reverse
- url을 어셈블하는 데 사용되는 문자열은 Yaf_Route_Regex::assemble()을 참조하세요.
메모: 이 매개변수는 2.3.0에서 도입되었습니다.
반환 값
Examples
예제 #1 Yaf_Route_Regex() 예제
<?php
/**
* Add a regex route to Yaf_Router route stack
*/
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(as of 2.3.0)() 예제
<?php
/**
* Use match result as MVC name
*/
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 and named capture ground(as of 2.3.0)() 예제
<?php
/**
* Use match result as MVC name
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new Yaf_Route_Regex(
"#^/product/(?<name>[^/]+)/([^/])+#i", //match request uri leading "/product"
array(
'controller' => ":name", // route to :name,
// which is named capture group 'name' in the match result as controller name
),
array(
2 => "id", // to get the first captrue in the match pattern.
)
)
);
?>
예제 #4 Yaf_Route_Regex() 예제
<?php
/**
* Add a regex route to Yaf_Router route stack by calling addconfig
*/
$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));
?>
기타
- Yaf_Router::addRoute() - 라우터에 새 경로 추가
- Yaf_Router::addConfig() - 라우터에 구성 정의 경로 추가
- Yaf_Route_Static
- Yaf_Route_Supervar
- Yaf_Route_Simple
- Yaf_Route_Rewrite
- Yaf_Route_Map