I add an EventSubscriberInterface In my project to redirect users do not have the right to access and the user not logged in, they do not have access to some pages and urls,my code work but my EventSubscriberInterface does not work If I want to get a page html, even when I add a die() in _construct nothing happened
page html example
/public/modules/story.html
My code
public function onKernelRequest(RequestEvent $event)
{
$request = $event->getRequest();
$RequestUri = strtok($request->getRequestUri(), '?');
if (strpos($RequestUri, '/public/modules') !== false) {
if(empty($_SESSION['_sf2_attributes']['_security.last_username'])){
//return new RedirectResponse($this->urlGenerator->generate('app_login'));
$route =$this->urlGenerator->generate('app_login');
$event->setResponse(new RedirectResponse($route));
}else{
$connection = $this->_em->getConnection();
$statement = $connection->prepare("SELECT * FROM eurotest_users eu
LEFT JOIN user_range ur On eu.id = ur.user_id
LEFT JOIN user_version uv On eu.id = uv.user_id
LEFT JOIN eurotest_module em On ur.range_id = em.module_range_id AND uv.version_id = em.module_version_id
where eu.email ='".$_SESSION['_sf2_attributes']['_security.last_username']."' and em.folder='".$RequestUri."' ");
$statement->execute();
$statement->fetchAll();
$counter = $statement->rowCount();
if($counter == 0){
$route =$this->urlGenerator->generate('app_home');
$event->setResponse(new RedirectResponse($route));
}
}
}
}