z7zmey / slim-found-handler
Slim 3 found handler
0.1
2016-04-02 12:00 UTC
Requires
- php: >=5.5
- slim/slim: ^3.0
Requires (Dev)
- phpunit/phpunit: 4.5.*
This package is not auto-updated.
Last update: 2024-12-27 11:07:29 UTC
README
Instalation
$ composer require z7zmey/slim-found-handler
Application Configuration
$app = new \Slim\App([ 'foundHandler' => function () { return new \z7zmey\SlimFoundHandler(); } ]);
Examples
You may use only required parameters
$app->get('/', function (\Slim\Http\Response $response) { $response->getBody()->write("Hello"); return $response; });
You can get access the route argument by using the same variable name
$app->get('/example1/{name}', function ($name) { echo "Hello, {$name}"; });
You can get access to all route arguments as array
$app->get('/example2/{first}/{second}', function (array $routeArguments) { echo "{$routeArguments['first']} {$routeArguments['second']}"; });
The sequence of parameters doesn't matter
use \Slim\Http\Response; use \Slim\Http\Request; $routeHandler = function ($first, Response $res, array $params, Request $req) { $second = $params['second']; $third = $req->getAttribute('route')->getArgument('third'); $res->getBody()->write("{$first} {$second} {$third}"); return $res; }; $app->get('/example3/{first}/{second}/{third}', $routeHandler);