Commit f1aeac5d by restyler Committed by Qiang Xue

addFlash method was implemented

parent 3d2cac53
...@@ -717,13 +717,35 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co ...@@ -717,13 +717,35 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
{ {
$counters = $this->get($this->flashParam, []); $counters = $this->get($this->flashParam, []);
$counters[$key] = $removeAfterAccess ? -1 : 0; $counters[$key] = $removeAfterAccess ? -1 : 0;
$_SESSION[$key] = $value;
$_SESSION[$this->flashParam] = $counters;
}
/**
* Appends new flash message to the specified key.
* @param string $key the key identifying the flash message.
* @param mixed $value flash message
* @param boolean $removeAfterAccess whether the flash message should be automatically removed only if
* it is accessed. If false, the flash message will be automatically removed after the next request,
* regardless if it is accessed or not. If true (default value), the flash message will remain until after
* it is accessed.
* @throws InvalidParamException if exising session variable is not array.
* @see getFlash()
* @see removeFlash()
*/
public function addFlash($key, $value = true, $removeAfterAccess = true)
{
$counters = $this->get($this->flashParam, []);
$counters[$key] = $removeAfterAccess ? -1 : 0;
if (!empty($_SESSION[$key])) { if (!empty($_SESSION[$key])) {
// If it's not an array, convert it to array
if (!is_array($_SESSION[$key])) {
$_SESSION[$key] = [$_SESSION[$key]];
}
$_SESSION[$key][] = $value; $_SESSION[$key][] = $value;
} else { } else {
$_SESSION[$key] = [$value]; $_SESSION[$key] = [$value];
} }
$_SESSION[$this->flashParam] = $counters; $_SESSION[$this->flashParam] = $counters;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment