phalcon——闪存消息
使用两种适配器来定义消息传递给Flasher后的行为:
(1)Phalcon\Flash\Direct:直接输出传递给flasher的消息
(2)Phalcon\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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)