I'm getting following error in my ZF2 FlashMessenger:
Call to a member function toArray() on array in /vendor/zendframework/zend-mvc/src/Controller/Plugin/FlashMessenger.php on line 306
FlashMessages will be rendered by my FlashMessageHelper:
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
use Zend\View\Helper\FlashMessenger;
class FlashMessageHelper extends AbstractHelper {
public function __invoke(FlashMessenger $flashMessenger) {
$flashMessenger->setMessageOpenFormat('<div%s><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><p class="text-center">');
$flashMessenger->setMessageSeparatorString('</p><p class="text-center">');
$flashMessenger->setMessageCloseString('</p></div>');
$flashMessenger->setAutoEscape(false);
echo $flashMessenger->render('error', array(
'alert',
'alert-dismissible',
'alert-danger'
));
echo $flashMessenger->render('info', array(
'alert',
'alert-dismissible',
'alert-info'
));
echo $flashMessenger->render('default', array(
'alert',
'alert-dismissible',
'alert-warning'
));
echo $flashMessenger->render('success', array(
'alert',
'alert-dismissible',
'alert-success'
));
}
}
?>
Does anybody know about this error? This is first time, that this error occured. Google and "zend-mvc" - repo - issues says nothing about this.
Thanks for your attention!
See this in ZF2 (Best Pratices):
The Plugin FlashMessenger , send your message to a waiting pool ( Through FlashMessenger Zend MVC Plugin ) which will be displayed on another page request ( Through ViewHelper FlashMessenger ) .
There are 4 types of messages that you can integrate with the Bootstrap Notifications ( error, info , default , success ) .
Now let's practice
In Action within the Controller , you must enter your message and your brand :
In View ( .phtml ) , you only need to use :
In View , if using Bootstrap :
Now 's a hack , if you want to view the FlashMessages on the screen without resquest ou redirect page ( Ideal for form errors , which you do not redirects or AJAX to another page ) , use this technique .
If you want to deepen better at it, follow the links Official Zend 2 documentation , gives a tried on available methods , will help a lot :
VIEW -> http://framework.zend.com/manual/current/en/modules/zend.view.helpers.flash-messenger.html
CONTROLLER -> http://framework.zend.com/manual/current/en/modules/zend.mvc.plugins.html#zend-mvc-controller-plugins-flashmessenger