Last active
July 16, 2021 16:15
-
-
Save mjamilasfihani/efec791f62d078d2d8ac7fe2505f0daf to your computer and use it in GitHub Desktop.
if you want create alert css or javascript with single function in CodeIgniter, here the code
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
# TESTED ON CODEIGNITER 3 & 4 | |
// ------------------------------------------------------------------------ | |
if (! function_exists('alert_css')) | |
{ | |
/** | |
* Alerts based on Bootstrap | |
* | |
* session()->setFlashdata('item', alert_css('internal server error')); | |
* | |
* @see https://getbootstrap.com/docs/4.3/components/alerts/ | |
*/ | |
function alert_css(string $message = '', string $colour = 'danger', string $title = 'notice') | |
{ | |
return '<div class="alert alert-'.strtolower($colour).' alert-dismissible fade show" role="alert"><strong>'.strtoupper($title).'!</strong> '.ucfirst($message).'.<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button></div>'; | |
} | |
} | |
// ------------------------------------------------------------------------ | |
if (! function_exists('alert_js')) | |
{ | |
/** | |
* Alerts based on JavaScript | |
* | |
* session()->setFlashdata('item', alert_js('internal server error')); | |
* | |
* @see https://www.w3schools.com/jsref/met_win_alert.asp | |
*/ | |
function alert_js(string $message = '') | |
{ | |
return '<script language="javascript">alert("'.ucfirst($message).'")</script>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment