Skip to content

Instantly share code, notes, and snippets.

@mjamilasfihani
Last active July 16, 2021 16:15
Show Gist options
  • Save mjamilasfihani/efec791f62d078d2d8ac7fe2505f0daf to your computer and use it in GitHub Desktop.
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
# 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">&times;</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