phalcon——闪存消息

使用两种适配器来定义消息传递给Flasher后的行为:

1PhalconFlashDirect:直接输出传递给flasher的消息

2PhalconFlashSession:将消息临时存放于会话中,以便消息可以在后面的请求中打印

                         出来

(如果你正在使用 PhalconDIFactoryDefault , 那么 PhalconFlashDirect 将会作为 “flash” 服务自动注册)

使用情况:(取决于发送消息后重定向的类型)

(1)转发:使用直接闪存

$this->flash->success("Your information was stored correctly!");

return $this->dispatcher->forward(array("action" => "index");

(2)HTTP重定向 直接渲染模板:使用会话缓存

$this->flashSession->success("Your information was stored correctly!");

return $this->response->redirect("contact/index");

这种情况需要手动在视图上打印消息:

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

(“flashSession”属性是在依赖注入容器中设置的闪存。 为了能成功使用flashSession消息者,你需要先启动 session 。)

目前支持四种消息类型:

$this->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.");

还可以自定义自己的消息类型:

$this->flash->message("debug", "this is debug message, you don't say");

利用自定义的CSS类来注册flash服务:

use PhalconFlashDirect as FlashDirect;

$di->set('flash', function () {

    $flash = new FlashDirect(array(

        'error'   => 'alert alert-danger',

        'success' => 'alert alert-success',

        'notice'  => 'alert alert-info',

        'warning' => 'alert alert-warning'

    ));

    return $flash;

});

输出消息示例:

<div class="alert alert-danger">too bad! the form had errors</div>

原文地址:https://www.cnblogs.com/wujuntian/p/4695211.html