From 76154b97766f7a4ef77d6d13480ceeafea7205e9 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 23 Sep 2013 20:38:54 -0400 Subject: [PATCH] Fixes #901: Added $delete parameter to Session::getFlash(). --- framework/yii/web/Session.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/framework/yii/web/Session.php b/framework/yii/web/Session.php index fc9fe16..92ec3ad 100644 --- a/framework/yii/web/Session.php +++ b/framework/yii/web/Session.php @@ -582,12 +582,22 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co * A flash message is available only in the current request and the next request. * @param string $key the key identifying the flash message * @param mixed $defaultValue value to be returned if the flash message does not exist. + * @param boolean $delete whether to delete this flash message right after this method is called. + * If false, the flash message will be automatically deleted after the next request. * @return mixed the flash message */ - public function getFlash($key, $defaultValue = null) + public function getFlash($key, $defaultValue = null, $delete = false) { $counters = $this->get($this->flashVar, array()); - return isset($counters[$key]) ? $this->get($key, $defaultValue) : $defaultValue; + if (isset($counters[$key])) { + $value = $this->get($key, $defaultValue); + if ($delete) { + $this->removeFlash($key); + } + return $value; + } else { + return $defaultValue; + } } /**