Ask Your Question
0

What is the way to obtain the current request's route path "/blog/{slug}" in Symfony?

asked 2023-07-10 21:26:48 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-07-10 21:40:02 +0000

djk gravatar image

You can use the getPathInfo() method of the Request object to obtain the current request's route path in Symfony. Here's an example:

use Symfony\Component\HttpFoundation\Request;

$request = Request::createFromGlobals();
$routePath = $request->getPathInfo(); // returns "/blog/{slug}"

You can use this code in your controller action to obtain the route path of the current request.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-10 21:26:48 +0000

Seen: 17 times

Last updated: Jul 10 '23