Skip to content

Instantly share code, notes, and snippets.

@COil
Created January 6, 2012 20:46
Show Gist options
  • Save COil/1572339 to your computer and use it in GitHub Desktop.
Save COil/1572339 to your computer and use it in GitHub Desktop.
Extending the Symfony2 session: snippet #2
<?php
// /app/src/COil/QuestBundle/Lib/mySession.php
namespace COil\QuestBundle\Lib;
use Symfony\Component\HttpFoundation\Session;
/**
* mySession object.
*/
class mySession extends Session
{
/**
* Add a "UserAnswer" object in session.
*
* @param type $userAnswer
*/
function addAnswer($userAnswer)
{
$answers = $this->get('answers', array());
$answers[] = $userAnswer;
$this->set('answers', $answers);
}
/**
* Return all the answers of the user.
*
* @return Array
*/
function getAnswers()
{
return $this->get('answers', array());
}
/**
* Set a "notice" flash message.
*
* @return String
*/
function setNotice($message)
{
return $this->setFlash('notice', $message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment