Created
November 9, 2012 16:23
-
-
Save rufinus/4046645 to your computer and use it in GitHub Desktop.
Type in flashmessenger
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
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 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
$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