diff --git a/lib/Cake/Controller/Component/FlashComponent.php b/lib/Cake/Controller/Component/FlashComponent.php index 3605481d9..6ae4ad61b 100644 --- a/lib/Cake/Controller/Component/FlashComponent.php +++ b/lib/Cake/Controller/Component/FlashComponent.php @@ -38,6 +38,7 @@ class FlashComponent extends Component { 'key' => 'flash', 'element' => 'default', 'params' => array(), + 'clear' => false ); /** @@ -82,7 +83,10 @@ class FlashComponent extends Component { } $options['element'] = $plugin . 'Flash/' . $element; - $messages = CakeSession::read('Message.' . $options['key']); + $messages = array(); + if ($options['clear'] === false) { + $messages = (array)CakeSession::read('Message.' . $options['key']); + } $newMessage = array( 'message' => $message, diff --git a/lib/Cake/Test/Case/Controller/Component/FlashComponentTest.php b/lib/Cake/Test/Case/Controller/Component/FlashComponentTest.php index f427be195..d20eab5b7 100644 --- a/lib/Cake/Test/Case/Controller/Component/FlashComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/FlashComponentTest.php @@ -131,6 +131,20 @@ class FlashComponentTest extends CakeTestCase { $result = CakeSession::read('Message.foobar'); $this->assertEquals($expected, $result); CakeSession::delete('Message.foobar'); + + $this->Flash->set('This is the first message'); + $this->Flash->set('This is the second message', array('clear' => true)); + $expected = array( + array( + 'message' => 'This is the second message', + 'key' => 'flash', + 'element' => 'Flash/default', + 'params' => array() + ) + ); + $result = CakeSession::read('Message.flash'); + $this->assertEquals($expected, $result); + CakeSession::delete('Message.flash'); } /**