Flashing Messages ================= Flash messages are used to notify the user about the state of actions he/she made or simply show information to the users. These kind of messages can be generated using this component. Adapters -------- This component makes use of adapters to define the behavior of the messages after being passed to the Flasher: +---------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------------------------+ | Adapter | Description | API | +=========+===============================================================================================+============================================================================+ | Direct | Directly outputs the messages passed to the flasher | :doc:`Phalcon\\Flash\\Direct <../api/Phalcon_Flash_Direct>` | +---------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------------------------+ | Session | Temporarily stores the messages in session, then messages can be printed in the next request | :doc:`Phalcon\\Flash\\Session <../api/Phalcon_Flash_Session>` | +---------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------------------------+ Usage ----- Usually the Flash Messaging service is requested from the services container, if you're using :doc:`Phalcon\\DI\\FactoryDefault <../api/Phalcon_DI_FactoryDefault>` then :doc:`Phalcon\\Flash\\Direct <../api/Phalcon_Flash_Direct>` is automatically registered as "flash" service: .. code-block:: php set('flash', function() { return new FlashDirect(); }); This way, you can use it in controllers or views by injecting the service in the required scope: .. code-block:: php flash->success("The post was correctly saved!"); } } There are four built-in message types supported: .. code-block:: php flash->error("too bad! the form had errors"); $this->flash->success("yes!, everything went very smoothly"); $this->flash->notice("this a very important information"); $this->flash->warning("best check yo self, you're not looking too good."); You can add messages with your own types: .. code-block:: php flash->message("debug", "this is debug message, you don't say"); Printing Messages ----------------- Messages sent to the flash service are automatically formatted with html: .. code-block:: html
flashSession->output() ?>
The attribute 'flashSession' is how the flash was previously set into the dependency injection container. You need to start the :doc:`session