I’ using Symfony2.1 and I want to do something like this:
When user comes to my page / I want redirect him to /welcome. When he clicks on link, which is in the /welcome then he should be redirected to / page, but then he should see main page (/) not welcome page again. How can I do this with routing? Is it possible?
In “normal” PHP I do this with sessions, what about Symfony2?
EDIT:
I solved the problem with sessions like this:
I have two routes: core_homepage (pattern /) and welcome_homepage (pattern /welcome).
//Controller for core:
public function indexAction()
{
$session = new Session();
$session->start();
if ($session->get('welcome_flag')=='0'){
return $this->render('MarkCoreBundle:Default:index.html.twig');
} else {
return $this->redirect($this->generateUrl('welcome_homepage'));
}
}
//Controller for welcome:
public function indexAction()
{
$session = new Session();
$session->start();
if ($session->get('welcome_flag') == '0'){
return $this->redirect($this->generateUrl('core_homepage'));
} else {
$session->set('welcome_flag', '0');
return $this->render('MarkWelcomeBundle:Default:index.html.twig');
}
}
If anybody has any other – solutions please post.
You can use sessions. In the controller for your ‘/’ route check if a flag is set in the session. If it is not, redirect to the ‘/welcome’ page. In the controller for the ‘/welcome’ route set this flag in the session.
Note that this will only last while the session is active. If you want a more permanent setting you will have to persist this to a database or something like that.