闪存消息(Flashing Messages) ============================= 闪存消息用于通知用户关于他/她产生的动作状态,或者简单地为用户显示一此信息。 这类消息可以使用这个组件来生成。 适配器(Adapters) ------------------ 这个组件使用了适配器来定义消息传递给Flasher后的行为: +---------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------------------------+ | 适配器 | 描述 | API | +=========+===============================================================================================+============================================================================+ | Direct | 直接输出传递给flasher的消息 | :doc:`Phalcon\\Flash\\Direct <../api/Phalcon_Flash_Direct>` | +---------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------------------------+ | Session | 将消息临时存放于会话中,以便消息可以在后面的请求中打印出来 | :doc:`Phalcon\\Flash\\Session <../api/Phalcon_Flash_Session>` | +---------+-----------------------------------------------------------------------------------------------+----------------------------------------------------------------------------+ 使用(Usage) ------------- 通常闪存消息都是来自服务容器的请求, 如果你正在使用 :doc:`Phalcon\\Di\\FactoryDefault <../api/Phalcon_Di_FactoryDefault>` , 那么 :doc:`Phalcon\\Flash\\Direct <../api/Phalcon_Flash_Direct>` 将会作为 "flash" 服务自动注册: .. code-block:: php set('flash', function () { return new FlashDirect(); }); 这样的话,你便可以在控制器或者视图中通过在必要的片段中注入此服务来使用它: .. code-block:: php flash->success("The post was correctly saved!"); } } 目前已支持的有四种内置消息类型: .. 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."); 你可以用你自己的类型来添加消息: .. code-block:: php flash->message("debug", "this is debug message, you don't say"); 输出信息(Printing Messages) ----------------------------- 发送给flash服务的消息将会自动格式成html: .. code-block:: html
flashSession->output() ?>
"flashSession"属性是先前在依赖注入容器中设置的闪存。 为了能成功使用flashSession消息者,你需要先启动 :doc:`session