私は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');
}
ビュー/レイアウト/ main.blade.php
<html>
<head>
<title>{{ $title }}</title>
</head>
<body>
{{ $content }}
</body>
</html>
ビュー/ welcome.blade.php
<p>Welcome.</p>
など。 2つの
コントローラ/ HomeController.php
protected $layout = 'layouts.main';
public function showWelcome()
{
$this->layout->content = View::make('welcome');
}
ビュー/レイアウト/ main.blade.php
<html>
<head>
<title>@yield('title')</title>
</head>
<body>
@yield('content')
</body>
</html>
ビュー/ welcome.blade.php
@section('title', 'Welcome')
@section('content')
// content
@stop
上記のベストコンベンションおよび/または利点は何ですか?
上記の例が正しいかどうかを正しく修正してください。 – Mediabeastnz