Issue
How can I test if a session exists in symfony?
Without the framework we proceed like this:
<?php
if( isset($_SESSION['login'])) {
echo 'Bonjour '.$_SESSION['login'].' vous etes connecté.<br>';
}
?>
How to do so with the session service in the symfony controller with the Request object?
Solution
In Symfony, session service is an instance of Symfony\Component\HttpFoundation\Session\Session. That said, session does provide several method to either check or manipulate session.
In your particular case, you would do something like this:
$session = $request->getSession();
if ( $session->has('login')){
$message = 'Bonjour '.$session->get('login').' vous etes connecté.<br>';
}
But, noting the comment from @Gerry, his question is a very valid one.
Hope this helps...
Answered By - Jovan Perovic Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.