Skip to content
This repository has been archived by the owner on Dec 4, 2019. It is now read-only.

Commit

Permalink
Display alerts using a view composer.
Browse files Browse the repository at this point in the history
  • Loading branch information
franzliedke committed Apr 19, 2014
1 parent 8404d91 commit d62e6c2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/FluxBB/Core/CoreServiceProvider.php
Expand Up @@ -34,6 +34,17 @@ public function boot()
* @return void
*/
public function register()
{
$this->registerBindings();
$this->registerViewComposers();
}

/**
* Register the IoC container bindings.
*
* @return void
*/
protected function registerBindings()
{
$this->app->bind('FluxBB\Models\GroupRepositoryInterface', function ($app) {
return new GroupRepository($app['cache']);
Expand All @@ -44,6 +55,16 @@ public function register()
});
}

/**
* Register any view composers.
*
* @return void
*/
protected function registerViewComposers()
{
$this->app['view']->composer('fluxbb::layout.main', 'FluxBB\View\AlertsComposer');
}

/**
* Get the services provided by the provider.
*
Expand Down
23 changes: 23 additions & 0 deletions src/FluxBB/View/AlertsComposer.php
@@ -0,0 +1,23 @@
<?php

namespace FluxBB\View;

use Illuminate\Session\Store;

class AlertsComposer
{
protected $session;


public function __construct(Store $session)
{
$this->session = $session;
}

public function compose($view)
{
if ($this->session->has('message')) {
$view->with('message', $this->session->get('message'));
}
}
}
6 changes: 5 additions & 1 deletion src/views/layout/main.blade.php
Expand Up @@ -2,7 +2,11 @@

<div id="brdmain">

@yield('alerts')
@if (isset($message))
<div class="alert alert-info">
{{{ $message }}}
</div>
@endif

@yield('main')

Expand Down

0 comments on commit d62e6c2

Please sign in to comment.