Skip to content

Commit ff6bf11

Browse files
committedDec 16, 2019
Add autodetect of flashdata messages
1 parent 10d1206 commit ff6bf11

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
 

‎bin/Alerts.php

+3
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ class Alerts extends \Tatter\Alerts\Config\Alerts
2424
foundation - [https://foundation.zurb.com/sites/docs/callout.html#making-closable]
2525
*/
2626
public $template = "Tatter\Alerts\Views\bootstrap";
27+
28+
// Whether to check session flashdata for common alert keys
29+
public $getflash = true;
2730
}

‎src/Alerts.php

+20
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ public function display()
104104
// clear alerts
105105
$this->session->remove($this->config->prefix . 'queue');
106106

107+
// Check for flashdata (if configured)
108+
if ($this->config->getflash)
109+
{
110+
if ($message = $this->session->getFlashdata('message'))
111+
{
112+
$alerts[] = ['class' => 'info', 'text' => $message];
113+
}
114+
elseif ($error = $this->session->getFlashdata('error'))
115+
{
116+
$alerts[] = ['class' => 'danger', 'text' => $error];
117+
}
118+
elseif ($errors = $this->session->getFlashdata('errors'))
119+
{
120+
foreach ($errors as $error)
121+
{
122+
$alerts[] = ['class' => 'danger', 'text' => $error];
123+
}
124+
}
125+
}
126+
107127
if (empty($alerts))
108128
return;
109129

‎src/Config/Alerts.php

+3
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ class Alerts extends BaseConfig
99

1010
// Template to use for HTML output
1111
public $template = "Tatter\Alerts\Views\bootstrap";
12+
13+
// Whether to check session flashdata for common alert keys
14+
public $getflash = true;
1215
}

0 commit comments

Comments
 (0)
Please sign in to comment.