kalkih / flashy
小型基于会话的闪存类,主要针对 Anax-MVC 编写。
dev-master
2014-05-15 08:13 UTC
Requires
- php: >=5.4
This package is not auto-updated.
Last update: 2024-09-24 07:55:25 UTC
README
一个用于存储和获取信息和消息的小型PHP闪存类。
Flashy 配备了一个简单且简约的预定义样式表。Flashy 支持四种不同的消息类型(信息、成功、警告和错误)。Flashy 还支持 Font Awesome。(下面提供代码示例说明)。
预览
函数
- add('消息类型', '你的消息') // 添加新的消息
- get('额外参数') // 获取消息作为HTML(可选:参数)
- clear() // 清除所有消息,也可从 get() 中调用
有效的消息类型
- 'info'
- 'success'
- 'warning'
- 'error'
有效的获取参数
- 'icons' // 在输出中添加 Font Awesome 图标
Anax-MVC 指令
将以下内容添加到 frontcontroller 的顶部。
// Get environment & autoloader, the $di & $app-object.
require __DIR__.'/config_with_app.php';
// Services
$di->setShared('flash', function() {
$flash = new \kalkih\Flash\Flash();
return $flash;
});
// Other services, modules, controllers here
// Starts the session (required by the Flashy class)
$app->session;
如果你想要使用捆绑的 flashy 样式表,请将以下代码添加到 frontcontroller 中(注意:你必须将样式表复制到你的 css 文件夹中才能使其生效)。
// Extra stylesheets
$app->theme->addStylesheet('css/flashy.css');
现在,你可以使用 Flashy 类了。
// From a route in the frontcontroller:
$app->flash->add('info', 'This is a info message');
$app->flash->add('success', 'This is a success message');
$app->flash->add('warning', 'This is a warning message');
$app->flash->add('error', 'This is a error message');
// From a controller:
$this->flash->add('info', 'This is a info message');
$this->flash->add('success', 'This is a success message');
$this->flash->add('warning', 'This is a warning message');
$this->flash->add('error', 'This is a error message');
要获取消息/消息并将其打印出来,只需将以下代码添加到一个视图中
$app->flash->get();
// or if in a view / controller
$this->flash->get();
输出应该如下所示
<div class="flashy_info">
This is a info message
</div>
<div class="flashy_success">
This is a success message
</div>
<div class="flashy_warning">
This is a warning message
</div>
<div class="flashy_error">
This is a error message
</div>
如果你支持 Font Awesome 并想在每个消息旁边显示相关的图标,请使用以下代码。
$app->flash->get('icons');
// or if in a view / controller
$this->flash->get('icons');
带有图标的输出应该如下所示
<div class="flashy_info">
<i class="fa fa-info-circle"></i>
This is a info message
</div>
<div class="flashy_success">
<i class="fa fa-check"></i>
This is a success message
</div>
<div class="flashy_warning">
<i class="fa fa-warning"></i>
This is a warning message
</div>
<div class="flashy_error">
<i class="fa fa-times-circle"></i>
This is a error message
</div>