Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jonathanmarvens/6017139 to your computer and use it in GitHub Desktop.
Save jonathanmarvens/6017139 to your computer and use it in GitHub Desktop.
<?php
class BaseController extends Controller {
private $application_name = 'The Cool Kid';
protected $layout = 'base';
// The cool kids' way of handling page titles.
protected $title = array(
'parent' => '',
'seperator' => '::',
'child' => '',
);
public function __construct() {
$instance = $this;
View::composer($this->layout, function ($view) use ($instance) {
$view->with('title', (implode(' ', $instance->title) . ' - ' . $instance->application_name));
});
}
protected function setupLayout() {
if (! is_null($this->layout)) {
$this->layout = View::make($this->layout);
}
}
}
<?php
class UserController extends \BaseController {
public function __construct() {
parent::__construct();
$this->title['parent'] = 'User';
}
public function getLogin() {
$this->title['child'] = 'Login';
if (Auth::check()) {
return 'Useless return...';
} else {
$this->layout->content = View::make('user.login');
}
}
}
<?php
Route::controller(
'user',
'UserController',
array(
'getLogin' => 'user_login',
)
);
Route::any('/', array(
'as' => 'base',
function () {
return Redirect::route('user_login');
},
));
<!doctype html>
<html>
<head>
<title>{{ $title }}</title>
</head>
<body>
@yield('content')
</body>
</html>
@extends('base')
@section('content')
<p>This is my body content.</p>
@stop
@sdebacker
Copy link

Thanks for that !

@jonathanmarvens
Copy link
Author

@sdebacker You're very welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment