在参数绑定之前检索URI

时间:2017-11-24 10:06:44

标签: php slim middleware slim-3

在我的Slim Framework 3路由器中,我有以下路由:use CertusAccuro_dev; go create user [NT AUTHORITY\SYSTEM] from login [NT AUTHORITY\SYSTEM];

在我的中间件中,当我检索请求URI时,它看起来像/account/{username}。在我的中间件中是否有可能在绑定username参数之前检索URI字符串?

在我的中间件中,我想检索我在路线中定义的字符串:/account/jordan

由于

2 个答案:

答案 0 :(得分:0)

路由中的参数在routeInfo中可用,这是一个请求属性,您可以将其与

一起使用
$routeInfo = $request->getAttributes('routeInfo');
$args = $routeInfo[2];
$username = $args['username'];

routeInfo仅在您启用determineRouteBeforeAppMiddleware设置时才可用:

$settings = ['determineRouteBeforeAppMiddleware' => true];
$app = new \Slim\App(['settings' => $settings]);

答案 1 :(得分:0)

您可以在$ request对象的route属性中找到有关路由的所有信息。 determineRouteBeforeAppMiddleware设置必须设置为true

$route = $request->getAttribute('route');

// do something with that information
$name = $route->getName();
$groups = $route->getGroups();
$methods = $route->getMethods();
$arguments = $route->getArguments();