Created
May 9, 2013 12:40
-
-
Save beeblebrox3/5547215 to your computer and use it in GitHub Desktop.
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 | |
/* | |
No Controller use | |
Sysfeedback::success("mensagem"); | |
Na View/Layout use | |
Sysfeedback::render(); | |
Isto irá mostrar todas as mensagens disponíveis | |
*/ | |
class Sysfeedback { | |
private static $types = array( | |
'success', | |
'error', | |
'info', | |
); | |
public static function render() { | |
foreach(self::$types as $type) { | |
$_type = 'sys-'.$type; | |
if(Session::has($_type)) { | |
self::html($type, Session::get($_type)); | |
Session::forget($_type); | |
} | |
} | |
} | |
private static function addMessage($type, $message) { | |
$messages = (array) Session::get($type); | |
$messages[] = $message; | |
Session::put($type, $messages); | |
} | |
private static function html($class, $messages) { | |
echo '<div class="alert alert-'.$class.'">'; | |
foreach($messages as $msg) { | |
echo $msg.'<br />'; | |
} | |
echo '</div>'; | |
} | |
public static function __callStatic($type, $args) { | |
if(!in_array($type, self::$types)) { | |
return false; | |
} | |
$type = 'sys-'.$type; | |
$message = $args[0]; | |
self::addMessage($type, $message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment