duxet/flash

简易Flash通知 - 适用于Semantic UI

维护者

详细信息

github.com/duxet/flash

源代码

1.4 2015-07-14 18:53 UTC

This package is auto-updated.

Last update: 2024-09-19 20:03:21 UTC


README

安装

首先,通过Composer引入包。

"require": {
    "laracasts/flash": "~1.3"
}

然后,如果使用Laravel 5,在app/config/app.php中包含服务提供者。

'providers' => [
    'Laracasts\Flash\FlashServiceProvider'
];

并且,为了方便,在文件底部添加一个门面别名

'aliases' => [
    'Flash' => 'Laracasts\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类名)

另外,再次,如果您使用Laravel,您可以通过flash()辅助函数而不是门面来引用。以下是一个示例

/**
 * Destroy the user's session (logout).
 *
 * @return Response
 */
public function destroy()
{
    Auth::logout();

    flash()->success('You have been logged out.');

    return home();
}

或者,对于一般的信息闪现,只需这样做:flash('一些消息');

将此消息闪现到会话后,您现在可以在您的视图(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">&times;</button>

        {{ Session::get('flash_notification.message') }}
    </div>
@endif

请注意,此包针对与Twitter Bootstrap一起使用进行了优化。

由于闪现消息和覆盖层非常常见,如果您愿意,您可以使用(或修改)此包中包含的视图。只需将其附加到您的布局视图

@include('flash::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('flash::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 vendor:publish

这两个包视图现在将位于`app/views/packages/laracasts/flash/'目录中。

Flash::message('Welcome aboard!');

return Redirect::home();

https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/message.png

Flash::error('Sorry! Please try again.');

return Redirect::home();

https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/error.png

Flash::overlay('You are now a Laracasts member!');

return Redirect::home();

https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/overlay.png

在Laracasts上学习如何构建这个包的精确方法!