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

Flash Messages

Hello, i want to create flash messages

At services file i have

$di->set( 'flash', function () { return new Phalcon\Flash\Direct(array( 'error' => 'alert alert-dismissable alert-danger', 'success' => 'alert alert-dismissable alert-success', 'notice' => 'alert alert-dismissable alert-info', )); } );

At controller i am doing

    $this->flash->success("Edit Successfull");
    $this->dispatcher->forward(array(
        'controller' => 'test',
        'action' => 'edit',
        'params'=>array($hotel_id)
    ));

And it works, but the url is changed to test/update from test/edit/id

What i want is the url remain to test/edit/id

cheers



4.0k

I guess that you post form data to test/update. If true, then: use not Phalcon\Flash\Direct but \Phalcon\Flash\Session and not forward but redirect.



6.2k
Accepted
answer

So i found the solution.... The service must be like this

$di->set( 'flash', function () { return new Phalcon\Flash\Direct( array( 'error' => 'alert alert-dismissable alert-danger', 'success' => 'alert alert-dismissable alert-success', 'notice' => 'alert alert-dismissable alert-info', )); } );

and the controller must be like this

$this->flash->success("Edit Successfull"); $this->views->disabled(); $this->responcse->redirect('controller/action');

And either using volt or phtml you must insert that

<p><?php $this->flashSession->output() ?></p>

cheers