티스토리 뷰
Routes
Basic
<?php require __DIR__ . '/../vendor/autoload.php'; $app = new \Slim\App(); $app->get('/', function($request, $response){ $response->write("Hello world"); return $response; }); $app->run(); ?>
$app에서
Method : get
Pattern : '/'
Action : function...
Dynamic routes
<?php require __DIR__ . '/../vendor/autoload.php'; $app = new \Slim\App(); $app->get('/hello/{name}', function($request, $response, $args){ $name = $args['name']; $name = htmlspecialchars($name); return $response->write("hello $name"); }); $app->run(); ?>
It's just Regex
$app->get('/user/{id:\d+}', $callable); $app->get('/hello/{name:[\w]+}', $callable); $app->get('/hello/{a:/{0,1}}{name:[\w]*}', $callable);
Named routes
// Name the route $app->get('/hello/{name}', function(...){...}) ->setName('hi'); // build link: $link = $app['router']->urlFor('hi', ['name' => 'Rob']); creates: /hello/Rob
'■ 백엔드 ■ > Slim' 카테고리의 다른 글
Twig views (0) | 2018.05.24 |
---|---|
Middleware (0) | 2018.05.24 |
index.php (0) | 2018.05.24 |
03. 웹서버 설정 (0) | 2018.05.23 |
02. 컴포저로 slim 설치하기 (0) | 2018.05.22 |
댓글