Skip to content

Instantly share code, notes, and snippets.

@rufinus
Created November 9, 2012 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rufinus/4046645 to your computer and use it in GitHub Desktop.
Save rufinus/4046645 to your computer and use it in GitHub Desktop.
Type in flashmessenger
class ShowMessages extends AbstractHelper
{
/**
* FlashMessenger
* @var unknown_type
*/
protected $_fm = NULL;
public function __construct(FlashMessenger $fm)
{
$this->_fm = $fm;
}
public function __invoke()
{
$html = '';
if (is_object($fm = $this->_fm)) {
$namespaces = array(
'ok' => array(
'color' => 'green',
'icon' => 'icon-tick'),
'error' => array(
'color' => 'red',
'icon' => 'icon-cross-round'),
'info' => array(
'color' => 'blue',
'icon' => 'icon-info-round')
);
foreach ($namespaces as $ns => $opt) {
$fm->setNamespace($ns);
$messages = array_merge(
$fm->getMessages(), $fm->getCurrentMessages()
);
foreach ($messages as $msg) {
$notification = 'notify("'.strtoupper($ns).'", "'.$this->getView()->translate($msg, 'admin').'", {groupSimilar: false, classes: "'.$opt['color'].'-gradient"});';
$this->getView()->inlineScript()->appendScript($notification);
}
$fm->clearMessages();
$fm->clearCurrentMessages();
}
}
return $html;
}
}
$this->getMessenger()->setNamespace('ok')->addMessage('a green one');
$this->getMessenger()->setNamespace('error')->addMessage('a red one');
$this->getMessenger()->setNamespace('info')->addMessage('a blue one');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment