duanjianlu0506
2015-10-27 14:24
浏览 37
已采纳

Symfony2 / Silex中间件

I am using silex to create an api and my routes look something similar to this:

$api = $app['controllers_factory'];
$users = $app['controllers_factory'];

$users->match('/', UsersController::action);

$api->mount('/users', $users);
$app->mount('/api', $api);

So the route would be baseurl/api/users

What I want to do now is to attach a before() to the $api controller group and enforce validation for the api, so any link prefixed with /api/...users, posts would require validation. But it seems that is not the way it works, when i put a before to the $api, it only works for the root of /api, not api/users or api/posts or api/categories, they require their own middlewares.

So my question is : how can I enforce everything after baseurl/api/... to require validation in a Silex enviroment.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题