How to empty messageQueue in J3.0

1287 views
Skip to first unread message

Peter van Westen

unread,
Sep 21, 2012, 8:21:53 AM9/21/12
to joomla-de...@googlegroups.com
Is there a way to empty the message queue in Joomla 3.0?
In Joomla 2.5 I can do:
JFactory::getApplication()->set('_messageQueue', '');

But that no longer works, as the JApplication is no longer an extend of JBase and therefore has no 'set' method.

Nils Rückmann

unread,
Sep 25, 2012, 7:38:08 PM9/25/12
to joomla-de...@googlegroups.com
Nope. Now way as long as we aren't using JApplicationWeb

elin

unread,
Sep 25, 2012, 10:09:17 PM9/25/12
to joomla-de...@googlegroups.com
I think someone needs to make a pull request with a replacement method.

(I think you meant that it doesn't extend JObject any more)

Elin

rolandd

unread,
Jan 23, 2013, 8:58:02 AM1/23/13
to joomla-de...@googlegroups.com
Hey guys,

Has there been any follow up on this?

Thanks.

rolandd

unread,
Mar 17, 2013, 12:29:52 PM3/17/13
to joomla-de...@googlegroups.com
Just to follow up myself, this seems to do it:

$session = JFactory::getSession();
$session->set('application.queue', null);

Michael Richey

unread,
Apr 25, 2013, 11:40:46 PM4/25/13
to joomla-de...@googlegroups.com
Doesn't work for me in 3.0, and that's because it's not part of the session until $app->redirect() occurs.  My preference is to kill the message when it occurs, if possible, or remove it from the queue immediately after it occurs if I have no control over it (ahem, PHPMailer)

I can see that messages are there by $app->getMessageQueue(); - so I know they exist in $app->_messageQueue, which is protected.

This is how I finally accomplished it.  Using Reflection, I can alter protected properties.  This function was written for removing a specific message, for which you know the exact message content.  You could easily adapt this to set the value to an empty array and kill the entire queue.  Pass it an application object, and the error message and voila!

function _killMessage($app,$error) {
        $appReflection = new ReflectionClass(get_class($app));
        $_messageQueue = $appReflection->getProperty('_messageQueue');
        $_messageQueue->setAccessible(true);
        $messages = $_messageQueue->getValue($app);
        foreach($messages as $key=>$message) {
                if($message['message'] == $error) {
                        unset($messages[$key]);
                }
        }
        $_messageQueue->setValue($app,$messages);
}

Alex Chartier

unread,
Aug 7, 2022, 11:35:51 AMAug 7
to Joomla! General Development

In case anyone comes back here, the CMSApplication in J4 changed the property name for the messageQueue and dropped the underscore prefix. Simply removing the underscore in the getProperty should work for you.
Reply all
Reply to author
Forward
0 new messages