Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add an addFlash method to easily add a single flash message.
  • Loading branch information
deviantintegral committed Oct 28, 2011
commit bc1fe9834dfe38c03f4dae349b50866664afe986
11 changes: 11 additions & 0 deletions src/Symfony/Component/HttpFoundation/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,17 @@ public function clearFlashes()
$this->oldFlashes = array('status' => array());
}

/**
* Adds a generic flash message to the session.
*
* @param string $type
*
* @return array
*/
public function addFlash($value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the opening bracket for methods need to be on a new line

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected in 543fb3e

$this->flashes['status'][] = $value;
}

public function save()
{
if (false === $this->started) {
Expand Down
5 changes: 5 additions & 0 deletions tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public function testFlash()
$this->session->setFlashes($flashes);

$this->assertSame($flashes, $this->session->getFlashes());

$this->session->clearFlashes();
$this->session->addFlash('foo');
$compare = $this->session->getFlashes();
$this->assertSame($compare, array(0 => 'foo'));
}

public function testFlashesAreFlushedWhenNeeded()
Expand Down