【发布时间】:2013-06-01 19:22:39
【问题描述】:
我一直在阅读 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
上述最佳约定和/或优点是什么?
【问题讨论】:
-
如果上面的例子是否正确,请纠正我!
标签: views laravel laravel-4 conventions blade