私のKernelRequestに問題があります。まず、ユーザーはプロファイルに関連付けられた権限のリストを持っています。バックオフィスでは、管理者は多くのプロファイルを作成したり、アクセスできる機能を作成したりできます。KernelRequestのリダイレクト時のSymfonyエラーajax
たとえば、ユーザーが/ profil/meに行くとします。私のKernelRequestはpath/profilにアクセスできるかどうかをチェックします。そうでない場合は、ユーザーを自宅にリダイレクトします。
残念ながら、これはAJAX呼び出しでは動作しません...私はfullcalendarを使用して、私のコンソールで、私はこのメッセージを持っている:
Uncaught SyntaxError: Unexpected token < router.js:9
Uncaught Error: The route "fullcalendar_loader" does not exist.
リダイレクトは正常に動作しますが、私はいつもこのメッセージを持って、なぜ?
public function onKernelRequest(GetResponseEvent $event)
{
$session = new Session();
$routeToRedirect = 'home_index';
$user = $session->get('JUNGO2_UTILISATEUR');
$profil = $user->getProfil()->getId();
$routeInterceptName = $event->getRequest()->get('_route');
$routeInterceptPath = $this->router->getRouteCollection()->get($routeInterceptName);
if (HttpKernel::MASTER_REQUEST != $event->getRequestType() || $routeInterceptName == "app_security_login" || $routeInterceptName == "home_index"){
return;
}
// if user are not in home
if ($routeToRedirect != $routeInterceptName) {
// For a profile, we list all privileges
$profil = $this->em->getRepository('AppBundle:Profil')->findOneById($profil);
$privileges = $this->em->getRepository('AppBundle:Privilege')->getPrivilegeByProfilNotNull($profil);
$routeInterceptPath = $routeInterceptPath->getPath();
//We retrieve the first word after the '/''
// Example: if the route is /user/profil, we just retrieve /user
$t = explode("/", $routeInterceptPath);
$routeInterceptPath = "/".$t[1];
// We look at whether the url corresponds to one of these privileges
foreach ($privileges as $privilege) {
$route = $privilege->getRoute();
$route = $this->router->getRouteCollection()->get($route)->getPath();
if($routeInterceptPath == $route){
return;
}
}
// ERROR WITH AJAX
$response = new RedirectResponse($this->router->generate($routeToRedirect));
$event->setResponse($response);
}
}
リダイレクトの最後の2行を削除しても、エラーメッセージは表示されません。しかしもちろん、リダイレクトはもうありません。
あなたは何が間違っているか考えていますか?
おかげ