view - Share data in every subview -
i have created layout contains header , main content changes regularly.
@include('tshop.includes.header') @yield('content') @include('tshop.includes.footer')
i have created below view composer in order pass products in basket pop dialog in header.
view::composer('tshop.includes.header', function($view) { $basket = app::make('basketinterface'); $view->with( 'productsiterator' , $basket->getiterator() ); });
the thing want share in views, including main content.
i tried utilize share
(and shares
) function thinking same view::share
isn't.
view::composer('tshop.includes.header', function($view) { $basket = app::make('basketinterface'); $view->share( 'productsiterator' , $basket->getiterator() ); });
i tried utilize view composer layout in vain.
view::composer('tshop.layouts.default', function($view) { $basket = app::make('basketinterface'); $view->shares( 'productsiterator' , $basket->getiterator() ); });
next placed below filter constructor.
$this->beforefilter(function() { $basket = app::make('basketinterface'); view::share('productsiterator' , $basket->getiterator()); });
and worked, utilize several controllers, it's not best thing do. know can create base of operations controller class , extend isn't there improve way do?
you may utilize app::before
event share info views globally using view::share
, example:
app::before(function($request) { $basket = app::make('basketinterface'); view::share( 'productsiterator' , $basket->getiterator() ); });
now, may access $productsiterator
view , btw, have used shares
instead of share
. may utilize view
composer instead of using view::share
, this:
view::composer('tshop.includes.header', function($view) { $basket = app::make('basketinterface'); homecoming $view->with( 'productsiterator' , $basket->getiterator() ); });
in case need utilize $view->with()
method instead of share
.
view laravel-4 blade
No comments:
Post a Comment