我想在Symfony2会话之前将sesion_liftime延长。在Symfony2中延长会话生存期
我向用户显示他将在几秒钟内注销,并且当他/她确认要扩展该会话时,我会向控制器发送一个ajax请求,以便扩展该会话。但问题是请求不起作用。
我尝试了几个不同的解决方案,但都没有工作。
<script type="text/javascript">
var timeoutID;
function delayedAlert() {
timeoutID = window.setTimeout(slowAlert, 15000);
}
function slowAlert() {
setTimeout(logout, 5500)
var r=confirm("You will be logout in 5 seconds!");
if (r==true)
{
$.ajax({
url: 'http://localhost/interactivo/web/app_dev.php/check',
xhrFields: {
withCredentials: true
}
});
alert("You wont be logout");
}
}
function logout() {alert("You are logout");};
delayedAlert();
</script>
/**
* @Route("/check")
*/
public function indexAction()
{
// FIRST ATTEMPT
// $value = 'something from somewhere';
//
// setcookie("TestCookie", $value);
// setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */
// setcookie("TestCookie", $value, time()+3600, "/~rasmus/", "example.com", 1);
// SECOND ATTEMPT
// header('Content-type: text/html; charset=utf-8');
// echo 'TEST';
// THIRD ATTEMPT
$session = $this->container->get('session');
$lastUsed = new \DateTime();
$lastUsed->setTimestamp($session->getMetadataBag()->getLastUsed());
return $this->render('GLHomeBundle:Default:sesion.html.twig', array('entities'=> $lastUsed));
}
我做错了什么?
的问题是,这个Ajax请求不调用控制器,我已经发现,如果我只会使用会话,它会自动更改lastModified的属性,所以iw将足以延长会话。但我怎么能调用这个indexAction? – user2576422
url:'/ check',这是肯定的,你可以通过使用url中的路由来调用你的控制器,如果它不起作用,你的问题在其他地方 – Peekmo