我一直在阅读Laravel 4文档,并制作了一个演示应用程序来帮助学习.
I couldn't find much documentation on the templating of views with blade and controllers. Which is the correct method or does it come down to personal preference?
E.g. 1
Controllers/HomeController.php
protected $layout = 'layouts.main';
public function showWelcome()
{
$this->layout->title = "Page Title";
$this->layout->content = View::make('welcome');
}
Views/layouts/main.blade.php
<html>
<head>
<title>{{ $title }}</title>
</head>
<body>
{{ $content }}
</body>
</html>
Views/welcome.blade.php
<p>Welcome.</p>
E.g. 2
Controllers/HomeController.php
protected $layout = 'layouts.main';
public function showWelcome()
{
$this->layout->content = View::make('welcome');
}
Views/layouts/main.blade.php
<html>
<head>
<title>@yield('title')</title>
</head>
<body>
@yield('content')
</body>
</html>
Views/welcome.blade.php
@section('title', 'Welcome')
@section('content')
// content
@stop
What is the best convention and/or advantages of the the above?