Created
February 20, 2021 19:24
-
-
Save matezito/dc11a92fb1326a17481817deedb03773 to your computer and use it in GitHub Desktop.
Flash 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
<?php | |
class Flash_Session { | |
static private $initialized = false; | |
public function __construct() | |
{ | |
if (self::$initialized) | |
return false; | |
self::$initialized = true; | |
} | |
/*** | |
* Set Flash messages | |
*/ | |
public static function set_flash_session($class, $msg) | |
{ | |
/** | |
* Init sessions if not | |
*/ | |
if (!session_id()) { | |
session_start(); | |
} | |
/** | |
* Create session if not exist | |
*/ | |
if (!isset($_SESSION['flash_messages'])) { | |
$_SESSION['flash_messages'] = ["hola"]; | |
} | |
$_SESSION['flash_messages'] = [ | |
'name' => $class, | |
'msg' => $msg | |
]; | |
return $_SESSION['flash_messages']; | |
} | |
/** | |
* Show Flash Messages | |
*/ | |
public static function show_flash_session() | |
{ | |
if (isset($_SESSION['flash_messages']) && !empty($_SESSION['flash_messages'])) { | |
echo '<div class="notice notice-' . $_SESSION['flash_messages']['name'] . ' is-dismissible"> | |
<p>' . $_SESSION['flash_messages']['msg'] . '</p> | |
</div>'; | |
} | |
unset($_SESSION['flash_messages']); | |
} | |
} | |
/** | |
* Set | |
* Flash_Session::set_flash_session('div-class','Message'); | |
*/ | |
/** | |
* Show message | |
* Flash_Session::show_flash_session() | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment