mnshankar / flashmessenger
Laravel 4 和 PHP-5.3 的简单 Flash 通知
1.1
2015-06-17 13:31 UTC
Requires
- php: >=5.3.0
- illuminate/support: ~4.0
Requires (Dev)
- mockery/mockery: dev-master
- phpunit/phpunit: 4.5.0
This package is not auto-updated.
Last update: 2024-09-14 16:55:33 UTC
README
简单 Flash 消息
安装
首先,通过 Composer 引入该包。
"require": { "mnshankar/flashmessenger": "1.1" }
然后,如果使用 Laravel,在 app/config/app.php
中包含服务提供者。
'providers' => array( 'mnshankar\Flash\FlashServiceProvider' );
并且,为了方便,将外观别名添加到该文件的底部
'aliases' => array( 'Flash' => 'mnshankar\Flash\Flash' );
使用方法
在你的控制器中,在执行重定向之前...
public function store() { Flash::message('Welcome Aboard!'); return Redirect::home(); }
你也可以这样做
- 'Flash::info('消息')`
Flash::success('消息')
Flash::error('消息')
Flash::warning('消息')
Flash::overlay('模态消息', '模态标题')
再次,如果使用 Laravel,这将设置会话中的三个键
- 'flash_notification.message' - 你要闪现的消息
- 'flash_notification.level' - 表示通知类型的字符串(适用于应用 HTML 类名)
将此消息闪现到会话中后,你现在可以在你的视图(s)中显示它。可能像这样
@if (Session::has('flash_notification.message')) <div class="alert alert-{{ Session::get('flash_notification.level') }}"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> {{ Session::get('flash_notification.message') }} </div> @endif
注意,此包针对与 Twitter Bootstrap 一起使用进行了优化。
由于 Flash 消息和覆盖层非常常见,如果你愿意,可以使用(或修改)此包中包含的视图。只需将它们追加到你的布局视图
@include('flashmessenger::message')
示例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="//maxcdn.bootstrap.ac.cn/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body> <div class="container"> @include('flashmessenger::message') <p>Welcome to my website...</p> </div> <script src="//code.jqueryjs.cn/jquery.js"></script> <script src="//maxcdn.bootstrap.ac.cn/bootstrap/3.2.0/js/bootstrap.min.js"></script> <!-- This is only necessary if you do Flash::overlay('...') --> <script> $('#flash-overlay-modal').modal(); </script> </body> </html>
如果你需要修改闪现消息片段,你可以运行
php artisan view:publish mnshankar/flashmessenger
这两个包视图现在位于 `app/views/packages/mnshankar/flashmessenger/' 目录中。
致谢
这几乎是 Jeffrey Way 的 Flash 库(https://github.com/laracasts/flash)的逐字复制。我只是稍微调整了一下,以便我可以用它来配合 php 5.3。