Flash Direct not working on Phalcon 3.0?

Phalcon 3.0; PHP 5.6 (nginx + fpm); OS: Debian 7.6

Does Flash Direct works correctly? I can't get it to output.

services.php (flash stuff):

use Phalcon\Flash\Direct as Flash;
use Phalcon\Flash\Session as FlashSession;

/**
 * Register the flash service with the Twitter Bootstrap classes
 */
$di->setShared('flash', function () {
    return new Flash(
        [
            'error'   => 'alert alert-danger',
            'success' => 'alert alert-success',
            'notice'  => 'alert alert-info',
            'warning' => 'alert alert-warning',
        ]
    );
});

/**
 * Register the session flash service with the Twitter Bootstrap classes
 */
$di->setShared('flashSession', function () {
    return new FlashSession(
        [
            'error'   => 'alert alert-danger',
            'success' => 'alert alert-success',
            'notice'  => 'alert alert-info',
            'warning' => 'alert alert-warning',
        ]
    );
});

Part of the controller that puts message(s) into flash service:


            // Form is INVALID, forward to edit form, data preserved
            if(!$form->isValid($this->request->getPost())) {
                foreach($form->getMessages() as $message) {
                    $this->flash->error($message);
                }
                //var_dump($this->flash->output());die;     // THIS OUTPUTS THE MESSAGE
                $this->dispatcher->forward(
                    [
                        'action' => 'edit',
                        'params' => [0 => $planId],
                    ]
                );

                return true;    
            }

View volt file (actually a template setTemplateAfter("general")), general.volt:

        {{ flash.output() }}            // THIS DOES'T SHOW ANYTHING
        {{ flashSession.output() }}     //THIS SHOWS WHEN I USE $this->flashSession

Phalcon 3.0.0 Use FlashDirect https://docs.phalconphp.com/en/latest/reference/flash.html

<?php

use Phalcon\Flash\Direct as FlashDirect;

// Register the flash service with custom CSS classes
$di->set('flash', function () {
    $flash = new FlashDirect(
        array(
            'error'   => 'alert alert-danger',
            'success' => 'alert alert-success',
            'notice'  => 'alert alert-info',
            'warning' => 'alert alert-warning'
        )
    );

    return $flash;
});


3.8k
edited Oct '17

Is this resoved ? if yes How ? I just made this in my confirmEmail action

$this->flash->success('The email was successfully confirmed');

    return $this->dispatcher->forward([
        'controller' => 'index',
        'action' => 'index'
    ]);

And in my indexController index view

<div class="flash">
    <?php
    echo $this->flashSession->output();
    echo $this->flash->output();
    ?>
</div>

And I have nothing when I am on my confirmEmail action url frowarded to index.

My flash and flashSession config are good

use Phalcon\Flash\Direct as Flash;

...

/**
 * Flash service with custom CSS classes
 */
$di->set('flash', function () {
    return new Flash([
        'error' => 'ui error message',
        'success' => 'ui success message',
        'notice' => 'ui info message',
        'warning' => 'ui warning message'
    ]);
});

/**
 * Flash service with custom CSS classes
 */
$di->set('flashSession', function () {
    return new \Phalcon\Flash\Session([
        'error' => 'ui error message',
        'success' => 'ui success message',
        'notice' => 'ui info message',
        'warning' => 'ui warning message'
    ]);
});

Using flashSession is working though, but int this case, with a forward, the flash should be working (and should be the service to use)

Was havint the same kind of issue and wasn't obvious to me at first but it is in the docs, I needed to use:

$flash->setImplicitFlush(false);

Then you can output it manually as you do with flash sessions.