使用 Routes 中的 PHP 框架 Slim 3,我这样做了:
// In routes :
$app->get('article/{id}-{slug}', function ($request, $response, $args) {
$class = new Site\ArticleController($args);
$class->show();
});
// In controllers :
public function show($args)
{
$sql = "SELECT * FROM articles WHERE id = $args['id'] AND slug = $args['slug']";
// ...
}
在 Laravel 5 中,这可以写成:
// In routes :
Route::get('article/{id}-{slug}', 'Site\ArticleController@show');
// In controllers :
public function show($id, $slug)
{
$sql = "SELECT * FROM articles WHERE id = $id AND slug = $slug";
// ...
}
我们可以对 Slim 3 做同样的事情吗?我的意思是:
$app::get('article/{id}-{slug}', 'Site\ArticleController@show');