Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Log flash messages?

Is there some smart way to send flash messages into log file?

$this->flash->error( "Some error message!" );

$this->logger->error( "Some error message!" );

I could extend \Phalcon\Flash\Direct::message() function, call DI, find logger and log it. Could events help in this case?



1.5k
Accepted
answer
edited Feb '16

I think the easiest solution is to create a new DI service:

$di->setShared("flashLoggerCombo", new FlashLoggerCombo() );

class FlashLoggerCombo extends \Phalcon\Mvc\User\Plugin
{
    public function error($message)
    {
        $this->logger->error($messsage);
        $this->flash->error($message);
    }

    // ...
}