Laravel 4控制器模板/刀片 - 正确的方法?

Med*_*tnz 23 views conventions laravel blade laravel-4

我一直在阅读Laravel 4文档,并且已经制作了一个演示应用程序来帮助学习.

我找不到很多关于使用刀片和控制器进行视图模板化的文档.哪种方法是正确的,还是归结为个人偏好?

例如1

控制器/ HomeController.php

protected $layout = 'layouts.main';

public function showWelcome()
{
    $this->layout->title = "Page Title";
    $this->layout->content = View::make('welcome');
}
Run Code Online (Sandbox Code Playgroud)

查看/布局/ main.blade.php

<html>
<head>
    <title>{{ $title }}</title>
</head>
<body>
    {{ $content }}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

查看/ welcome.blade.php

<p>Welcome.</p>
Run Code Online (Sandbox Code Playgroud)

例如2

控制器/ HomeController.php

protected $layout = 'layouts.main';

public function showWelcome()
{
    $this->layout->content = View::make('welcome');
}
Run Code Online (Sandbox Code Playgroud)

查看/布局/ main.blade.php

<html>
<head>
    <title>@yield('title')</title>
</head>
<body>
    @yield('content')
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

查看/ welcome.blade.php

@section('title', 'Welcome')
@section('content')
// content
@stop
Run Code Online (Sandbox Code Playgroud)

上述最佳惯例和/或优势是什么?

Sam*_*amV 5

我不在控制器中存储任何布局信息,而是通过以下方式将其存储在视图中

@extends('layouts.master')
Run Code Online (Sandbox Code Playgroud)

当我需要在控制器中返回一个视图时,我使用:

return \View::make('examples.foo')->with('foo', $bar);
Run Code Online (Sandbox Code Playgroud)

我更喜欢这种方法,因为视图决定了要使用的布局,而不是控制器——这需要重构。