slim routeplaceholder
2020.02.27 08:51
슬래시 무한
http://www.slimframework.com/docs/v3/objects/router.html
http://www.slimframework.com/docs/v4/objects/routing.html#route-placeholders
Route placeholders
Each routing method described above accepts a URL pattern that is matched against the current HTTP request URI. Route patterns may use named placeholders to dynamically match HTTP request URI segments.
Format
A route pattern placeholder starts with a {
, followed by the placeholder name, ending with a }
. This is an example placeholder named name
:
$app = new \Slim\App();
$app->get('/hello/{name}', function ($request, $response, $args) {
echo "Hello, " . $args['name'];
});
Optional segments
To make a section optional, simply wrap in square brackets:
$app->get('/users[/{id}]', function ($request, $response, $args) {
// responds to both `/users` and `/users/123`
// but not to `/users/`
});
Multiple optional parameters are supported by nesting:
$app->get('/news[/{year}[/{month}]]', function ($request, $response, $args) {
// reponds to `/news`, `/news/2016` and `/news/2016/03`
});
For “Unlimited” optional parameters, you can do this:
$app->get('/news[/{params:.*}]', function ($request, $response, $args) {
$params = explode('/', $args['params']);
// $params is an array of all the optional segments
});
In this example, a URI of /news/2016/03/20
would result in the $params
array containing three elements: ['2016', '03', '20']
.
Regular expression matching
By default the placeholders are written inside {}
and can accept any values. However, placeholders can also require the HTTP request URI to match a particular regular expression. If the current HTTP request URI does not match a placeholder regular expression, the route is not invoked. This is an example placeholder named id
that requires one or more digits.
$app = new \Slim\App();
$app->get('/users/{id:[0-9]+}', function ($request, $response, $args) {
// Find user identified by $args['id']
});
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
21 | nginx site enable | 꿈돌이 | 2024.09.07 | 70 |
» | slim routeplaceholder | 꿈돌이 | 2020.02.27 | 4291 |
19 | slim 4 , Intelephense | 꿈돌이 | 2020.01.17 | 363 |
18 | axios post로 데이터 안 넘어갈 때 체크할 거 | 꿈돌이 | 2018.10.24 | 662 |
17 |
윈도우에서 사설인증서로 https localhost 사용하기
![]() | 꿈돌이 | 2018.08.24 | 329 |
16 | php obfuscator | 꿈돌이 | 2018.01.31 | 267 |
15 | DB 순번 시퀀스 초기화 | 꿈돌이 | 2017.12.25 | 12970 |
14 | Vue.js td내 input 태그에서 v-for | 꿈돌이 | 2017.12.19 | 676 |
13 |
Vue Slim으로 카테고리 만들기
![]() | 꿈돌이 | 2017.11.10 | 298 |
12 | Doctrine DBAL 메모 | 꿈돌이 | 2017.10.27 | 301 |
11 |
Vue Tree view with Single file component
![]() | 꿈돌이 | 2017.09.29 | 437 |
10 | PHP 내장 웹서버 띄우기 | 꿈돌이 | 2017.09.04 | 602 |
9 |
vue-slim-medoo boilerplate
![]() | 꿈돌이 | 2017.06.04 | 327 |
8 |
Vue boilerplate
![]() | 꿈돌이 | 2017.06.02 | 473 |
7 |
Slim boilerplates
![]() | 꿈돌이 | 2017.06.02 | 257 |
6 | Windows에서 Composer로 slim 설치하기 | 꿈돌이 | 2017.06.01 | 620 |
5 | 코드이그나이터 3.1.3에서 HMVC 오류 대응 | 꿈돌이 | 2017.03.01 | 541 |
4 | CodeIgniter - Helper 폐기 항목 | 꿈돌이 | 2016.06.14 | 1262 |
3 | CodeIgniter - Class Libraries 폐기 항목 | 꿈돌이 | 2016.06.14 | 481 |
2 | Windows에서 Composer로 CodeIgniter 설치하기 | 꿈돌이 | 2016.06.06 | 1215 |