is there a way to redirect from a createAction to listAction in SonataAdminBundle?
I'm needing it to redirect user when access denied.
$curUser = $this->getConfigurationPool()->getContainer()->get('security.token_storage')->getToken()->getUser();
if ($this->getSubject()->getId() && $this->getSubject()->getUser()) {
if ($this->getSubject()->getUser() != $curUser) {
REDIRECT HERE
}
}
First you need to add use RedirectResponse class.
use Symfony\Component\HttpFoundation\RedirectResponse;
After that :
$curUser = $this->getConfigurationPool()->getContainer()->get('security.token_storage')->getToken()->getUser();
if ($this->getSubject()->getId() && $this->getSubject()->getUser()) {
if ($this->getSubject()->getUser() != $curUser) {
$redirection = new RedirectResponse($this->getConfigurationPool()->getContainer()->get('router')->generate('your_route_name'));
$redirection->send();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.