desmart / laravel-layout
Simple page structure controller for Laravel4
Installs: 611
Dependents: 3
Suggesters: 0
Security: 0
Stars: 10
Watchers: 14
Forks: 0
Open Issues: 2
Requires
- php: >=5.4.0
- illuminate/support: 4.2.x
Requires (Dev)
- illuminate/container: 4.2.x
- illuminate/http: 4.2.x
- illuminate/routing: 4.2.x
- illuminate/view: 4.2.x
- mockery/mockery: 0.8.*
This package is auto-updated.
Last update: 2022-02-01 12:24:17 UTC
README
Installation
Add desmart\laravel-layout
as a requirement to composer.json:
{ "require": { "desmart/laravel-layout": "1.2.*" } }
Update your packages with composer update
or install with composer install
.
In app/config/app.php add:
'DeSmart\Layout\LayoutServiceProvider',
to providers'Layout' => 'DeSmart\Layout\Facades\Layout',
to aliases.
Overview
This package provides DeSmart\Layout\Controller
class which works like normal page controller.
However it can be used to describe complete page structure.
To do this simply define $layout
which is basic page template, and $structure
which is an array with section block definition.
Section block is a list of callbacks (let's call them actions) which will be run and put in a defined place in template.
Sample page template
<!DOCTYPE html> <html> <head></head> <body> <div class="container"> <div class="main">{{ $main }}</div> <div class="right">{{ $right }}</div> </div> </body> </html>
Sample controller
<?php class SampleController extends \DeSmart\Layout\Controller { protected $layout = 'layouts.default'; protected $structure = array( 'main' => array( 'FancyBanner@show', 'TopStories@show', ), 'right' => array( 'Menu@showTopProducts', ), ); public function showProducts() { $this->structure['main'] = array( 'Products@showAll', ); return $this->execute(); } public function showOne() { $this->changeLayout('layouts.product'); $this->structure['main'] = array( 'Products@showOne', ); return $this->execute(); } }
Sample route
<?php Route::get('/', 'SampleController@execute'); Route::get('/products', 'SampleController@showProducts'); Route::get('/products/{product_id}', 'SampleController@showOne');
Actions
Each action is a callback string which will be called during DeSmart\Layout\Controller@execute
call.
Every action can get params defined in route, just define them as function arguments (public function showOne($product_id) {}
).
Layout facade
This package provides Layout
facade with method dispatch
.
It can be used to execute action directly in template.
<header>{{ Layout::dispatch('HomeController@head') }}</header>
dispatch()
can take array argument with named callback arguments:
class FancyController { public function test($name, $title = 'sir. ') {} } <header> {{ Layout::dispatch('FancyController@test', array('name' => 'Hans')) }} </header>
Notice, that it takes care with default arguments.
Warning
This package is provided as is. For now it's only a concept and the whole idea can change.
Just treat it as early alpha version.