phalcon——闪存消息

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

1Phalcon\Flash\Direct:直接输出传递给flasher的消息

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

                         出来

(如果你正在使用 Phalcon\DI\FactoryDefault , 那么 Phalcon\Flash\Direct 将会作为 “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 Phalcon\Flash\Direct 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值