php - 如何使用引导程序将关闭图标添加到 phalcon 会话闪存消息
问题描述
我的服务配置如下;
$di->set('flashSession', function () {
return new FlashSession([
'error' => 'alert alert-danger',
'success' => 'alert alert-success',
'notice' => 'alert alert-info',
'warning' => 'alert alert-warning'
]);
});
引导程序警报消息可以正常工作,但没有关闭图标。
如何使我的所有会话警报消息都具有关闭图标。
解决方案
这是会话闪存消息的快速消息。
在库目录中创建一个名为 BootstrapFlash.php 的文件
粘贴下面的代码
class BootstrapFlash extends \Phalcon\Flash\Session{
public function __construct(){
/* Pass html tags as receieved without reformating */
parent::__construct();
$this->setAutoescape(false);
}
public function message($type, $message){
/* map the right class based on the message type */
$types = array(
'success' => 'success',
'notice' => 'info',
'error' => 'danger',
'warning' => 'warning'
);
$type = $types[$type];
/* pretty title */
$upper_type = strtoupper($type);
/* Custom Alert Message with dismissible */
$message = "<div class=\"alert alert-{$type} alert-dismissible\" role=\"alert\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button><strong>{$upper_type}!</strong> {$message}</div>";
parent::message($type, $message);
}
}
在 config 目录中的 service.php 文件中,如下设置您的 flash 会话;
$di->set('flashSession', function () {
/* Custom file available in the library Directory */
return new BootstrapFlash();
});
这样,您的 Flash 会话消息将具有关闭关闭按钮。
您也可以根据需要修改会话警报消息。
推荐阅读
- python - Wagtail:将 vanilla Django 模型实例传递给小部件
- java - Android Studio 网格布局无法正常工作
- c++ - 使用函数指针返回地址
- http - 如何向用户的浏览器传达它发出的 POST 请求没有副作用?
- laravel - Laravel 形式未定义
- database - 优化数据库设计以最大化数据冗余并增加信息的可访问性
- mysql - 如何将新条目添加到 mysql 表中,但仅适用于 1 列,同时保留所有其他列数据
- python-3.x - 变量在函数中运行时表示它为 False,但随后又恢复为 True
- python - 在 Python/R 中使用 SLINK 后分离集群
- netlogo - 如何确定我需要在 netlogo 中执行的运行次数以减少随机化的影响?