Symfony将当前URI段作为数组


Symfony get current URI slugs as array?

在Symfony中,如何将当前URI slugs作为数组?

www.mysite.com/this/that/test/hello/world/7?whatever=true

使用什么命令来获得以下数组:

[0] => 'this',
[1] => 'that',
[2] => 'test',
[3] => 'hello',
[4] => 'world',
[5] => '7'

尝试以下操作:

explode('/', $request->getPathInfo());

(我实际上不知道从哪里获得请求对象,所以您可能需要重命名变量)

这应该有效:

 explode('/',$this->getContext()->getRouting()->getCurrentInternalUri());