We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

No styling on flash messages

Hi All,

I am using the phalcon flash messages to display notifications. I have the flash service registered in my application and the error messages display as soon as I do a redirect but there is no styling information.

Here is the code :

    // registering the flash service
    $di->set('flash', function () {
        return new Flash(array(
            'error' => 'alert alert-error',
            'success' => 'alert alert-success',
            'notice' => 'alert alert-info'
        ));    
    });

    // using the redirect http method to display the error message on the controller    
     $this->flashSession->error("Wrong email/password");
     return $this->response->redirect('login'); 
     // code in view template
         <!-- error messages -->
         <div class="row">
            <?php $this->flashSession->output(); ?>
         </div>

This is what it produces on my view :

<div class="errorMessage">Wrong email/password combination</div>

As you can see there is no styling. I have the bootrap.css file loaded.

What am I doing wrong?

Thanks



6.6k
Accepted
answer
edited Sep '14

You use the flashSession for your messages but you configured the "basic" flash messenger. Configure the flashSession and I'm sure it will work :)

<?php
$this->di->set("flashSession", function () {
            $flashSession = new FlashSession();
            $flashSession->setCssClasses(array(
                'error' => 'alert alert-danger',
                'success' => 'alert alert-success',
                'notice' => 'alert alert-info'
            ));
            return $flashSession;
        });


22.8k

Hey @skollro it works!! I had to use the namespace like follows :

use Phalcon\Flash\Session as FlashSession;

and after that it worked just fine :)



6.6k

oh sorry i didn't see that I've used an alias for the namespace, just copied it from a project of mine ;)