27 $this->array = USession::get ( self::FLASH_BAG_KEY, [ ] );
29 EventsManager::addListener(ViewEvents::BEFORE_RENDER,
function($_, &$data) {
32 EventsManager::addListener(ViewEvents::AFTER_RENDER,
function(){
33 if($this->autoClear) {
46 public function addMessage(
string $content,
string $title = NULL,
string $type =
'info',
string $icon =
null): void {
47 $this->array [] = new
FlashMessage ( $content, $title, $type, $icon );
57 public function addMessageAndSave(
string $content,
string $title = NULL,
string $type =
'info',
string $icon =
null): void {
58 $this->addMessage($content,$title,$type,$icon);
59 USession::set ( self::FLASH_BAG_KEY, $this->array );
69 foreach ( $this->array as $msg ) {
70 if ($msg->getType () == $type) {
90 USession::delete ( self::FLASH_BAG_KEY );
102 return $this->array [$this->position];
105 public function key(): int {
106 return $this->position;
114 return isset ( $this->array [$this->position] );
118 $this->array =
USession::set ( self::FLASH_BAG_KEY, $this->array );
125 return $this->autoClear;
132 $this->autoClear = $autoClear;
Base class for controllers.
Bag for Session Flash messages Ubiquity\utils\flash$FlashBag This class is part of Ubiquity.
addMessage(string $content, string $title=NULL, string $type='info', string $icon=null)
Adds a temporary new message to the bag.
setAutoClear(bool $autoClear)
getMessages(string $type)
Returns all the message of a type in the bag.
getAll()
Returns all the messages.
addMessageAndSave(string $content, string $title=NULL, string $type='info', string $icon=null)
Adds and saves a message in the bag.
__construct(bool $autoClear=true)
Http Session utilities This class is part of Ubiquity.