Answer the question
In order to leave comments, you need to log in
How to get _security.default.target_path in controller?
Hello.
I also have social login links on the login page, which can be passed some internal path so that after a redirect from the social network, the user returns to the URI from which he got to the login.
Inside Symfony, the _security.default.target_path parameter in the session is responsible for this. The referrer is not suitable, because it contains not always correct data (for example, I go from a publicly available product /good/{good_id}
page to a payment page /good/{good_id}/buy
that already requires authentication, being not logged in, and I get a 302 redirect to /signin. In this case, the referrer will contain /good/{good_id}
, and not expected /good/{good_id}/buy)
..
In this case, the session contains the correct parameter, which I would like to get.
Of course, you can do something like
$target = $this->get('session')->get('_security.default.target_path', '/')
, but you yourself understand the reliability and correctness of this decision. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question