来自http://laravel.com/docs/4.2/templates:
(控制器)
class UserController extends BaseController {
/**
* The layout that should be used for responses.
*/
protected $layout = 'layouts.master';
/**
* Show the user profile.
*/
public function showProfile()
{
$this->layout->content = View::make('user.profile');
}
}
(模板)
@extends('layouts.master')
@section('sidebar')
<p>This is appended to the master sidebar.</p>
@stop
@section('content')
<p>This is my body content.</p>
@stop
为什么layouts.master
需要调用两次?$this->layout
需要设置的事实layouts.master
和需要传递的事实layouts.master
似乎@extends()
......多余和不必要的。