Created
February 14, 2014 22:26
-
-
Save gpedro/9010740 to your computer and use it in GitHub Desktop.
Alert Helper with Bootstrap 3 style for Codeigniter
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
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
function _base_alert($type, $title, $message = false) | |
{ | |
$CI =& get_instance(); | |
$alert = json_encode(array('type' => $type, 'head' => $title, 'message' => $message)); | |
$CI->session->set_flashdata('alert', $alert); | |
} | |
function process_alert($json) | |
{ | |
$config = json_decode($json); | |
$icon = ''; | |
switch($config->{'type'}) | |
{ | |
case 'success': | |
$icon = 'ok'; | |
$head = 'Success Message'; | |
break; | |
case 'info': | |
$icon = 'info-sign'; | |
$head = 'Info Message'; | |
break; | |
case 'warning': | |
$icon = 'record'; | |
$head = 'Warning Message'; | |
break; | |
case 'danger': | |
$icon = 'hand-right'; | |
$head = 'Danger Message'; | |
break; | |
} | |
$head = (!empty($config->{'head'})) ? $config->{'head'} : $head; | |
$msg = (empty($config->{'message'})) ? '' : '<hr class="message-inner-separator"><p>'.$config->{'message'}.'</p>'; | |
return '<section id="alert"><div class="container"><div class="alert alert-'.$config->{'type'}.'"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><span class="glyphicon glyphicon-'.$icon.'"></span> <strong>'.$head.'</strong>'. $msg .'</div></div></section>'; | |
} | |
if (!function_exists('success')) | |
{ | |
function success($title, $message = false) | |
{ | |
_base_alert('success', $title, $message); | |
} | |
} | |
if (!function_exists('warning')) | |
{ | |
function warning($title, $message = false) | |
{ | |
_base_alert('warning', $title, $message); | |
} | |
} | |
if (!function_exists('error')) | |
{ | |
function error($title, $message = false) | |
{ | |
_base_alert('danger', $title, $message); | |
} | |
} | |
if (!function_exists('info')) | |
{ | |
function info($title, $message = false) | |
{ | |
_base_alert('info', $title, $message); | |
} | |
} | |
/* End of file alert_helper.php */ | |
/* Location: ./application/helpers/alert_helper.php */ |
Seems to be unfinished....
How to call 👍
$this->session->set_flashdata('alert', 'Hello World !');
Put this code in your head
<?php if ($_SESSION['alert'] != ''): ?>
<script type="text/javascript">
toastr.success('<?php echo $this->session->flashdata("alert);?>');
</script>
<?php endif; ?>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How i use this alert helper class ? how i call ?? please help me thanks