views:

738

answers:

4

hi all, i am using FlashMessenger helper to set messages, but i am unable to retrieve messages using getMessages() method. it returns null. here is my sample code:

<?php
class Admin_TestController extends Zend_Controller_Action
{
    protected $_flashMessenger = null;

    public function init()
    {
        $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
        $this->initView();
    }

    public function myAction()
    {
        $this->_flashMessenger->addMessage('test message');

        $this->_helper->Redirector("mynextrequest");
    }

    public function mynextrequestAction()
    {
        zend_debug::dump($this->_flashMessenger->getMessages());
        $this->render();
    }
}
A: 

aside from the function/classname capitalization issues, make sure your Zend_Session is set up, started, and has a storage method that works. It will use your session storage method that comes from a new Zend_Session_Namespace('FlashMessenger')

Justin
A: 

i upgrade from php 5.2.0 to 5.2.9 and the problem solved. thank you anyway.

rahim asgari
A: 

There are PHP 5.2.x Versions, that have a problem with

// Zend_Controller_Action_Helper_FlashMessenger::addMessage() (line 143)
self::$_session->{$this->_namespace}[] = $message;

Upgrading PHP would be a solution (as you did) or replacing the above line with the following code:

$messages = self::$_session->{$this->_namespace};

$messages[] = $message;

self::$_session->{$this->_namespace} = $messages;

Octavian
A: 

i had a problem that came from having two pieces of ajax that used the flashMessanger and were finishing loading in random order. so the first piece of ajax was sometimes loaded first and thus using the messages and left none for the second. and i was expecting the error mesages in the second piece of ajax and wondered why do they show just approx 50% of the cases.