Last active
January 3, 2016 11:38
-
-
Save tamboer/8457039 to your computer and use it in GitHub Desktop.
ZF FlashMessenger example
This file contains hidden or 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 TestController extends Zend_Controller_Action { | |
| /** | |
| * FlashMessenger | |
| * | |
| * @var Zend_Controller_Action_Helper_FlashMessenger | |
| */ | |
| protected $_flashMessenger = null; | |
| public function init(){ | |
| $this->_flashMessenger = | |
| $this->_helper->getHelper('FlashMessenger'); | |
| $this->initView(); | |
| } | |
| public function indexAction() { | |
| /** | |
| * default method of getting | |
| * Zend_Controller_Action_Helper_FlashMessenger instance | |
| * on-demand | |
| */ | |
| $this->_flashMessenger->addMessage('Record Saved!'); | |
| } | |
| public function nextAction() { | |
| $this->view->messages = $this->_flashMessenger->getMessages(); | |
| $this->render(); | |
| } | |
| } | |
| ;?> | |
| *****************************include alertify.js ******************************************* | |
| *****************************layout ******************************************* | |
| <?php if (isset($this->messages)): ?> | |
| <?= $this->partial('partials/messenger.phtml', array('messages' => $this->messages)); ?> | |
| <?php endif ?> | |
| *****************************partial ******************************************* | |
| <?php if (!empty($this->messages['success'])): ?> | |
| <script> | |
| <?php | |
| foreach ((array) $this->messages['success'] as $key => $msg) { | |
| echo 'alertify.log("' . $msg . '", "success", 2000);'; | |
| } | |
| ?> | |
| </script> | |
| <?php endif ?> | |
| <?php if (!empty($this->messages['error'])): ?> | |
| <script> | |
| <?php | |
| foreach ((array) $this->messages['error'] as $key => $msg) { | |
| echo 'alertify.log("' . $msg . '", "error", 2000);'; | |
| } | |
| ?> | |
| </script> | |
| <?php endif ?> | |
| <?php if (!empty($this->messages['info'])): ?> | |
| <script> | |
| <?php | |
| foreach ((array) $this->messages['info'] as $key => $msg) { | |
| echo 'alertify.log("' . $msg . '", "notification", 2000);'; | |
| } | |
| ?> | |
| </script> | |
| <?php | |
| endif ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment