Last active
July 10, 2017 03:41
-
-
Save gamaup/6b591734a313f606afbd761af09358be to your computer and use it in GitHub Desktop.
Bootstrap flash alert using Tiga Session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Flash_Alert { | |
private $session; | |
function __construct() { | |
$this->session = new \Tiga\Session(); | |
} | |
public function error($message) { | |
$this->add('danger', $message); | |
} | |
public function success($message) { | |
$this->add('success', $message); | |
} | |
public function info($message) { | |
$this->add('info', $message); | |
} | |
public function warning($message) { | |
$this->add('warning', $message); | |
} | |
public function add($type, $message) { | |
$old = $this->session->get('flash_alert_'.$type); | |
$this->session->set('flash_alert_'.$type, $old.'<div>'.$message.'</div>'); | |
} | |
public function display() { | |
if ($this->session->has('flash_alert_danger')) { | |
echo '<div class="alert dismissable alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'.$this->session->pull('flash_alert_danger').'</div>'; | |
} | |
if ($this->session->has('flash_alert_info')) { | |
echo '<div class="alert dismissable alert-info"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'.$this->session->pull('flash_alert_info').'</div>'; | |
} | |
if ($this->session->has('flash_alert_success')) { | |
echo '<div class="alert dismissable alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'.$this->session->pull('flash_alert_success').'</div>'; | |
} | |
if ($this->session->has('flash_alert_warning')) { | |
echo '<div class="alert dismissable alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'.$this->session->pull('flash_alert_warning').'</div>'; | |
} | |
} | |
} | |
$flash = new Flash_Alert(); | |
$flash->error( "Something happens" ); | |
$flash->display(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment