Tôi đã đọc qua tài liệu Laravel 4 và đã tạo một ứng dụng demo để giúp học tập.Laravel 4 Controller Templating/Blade - Phương pháp đúng?
Tôi không thể tìm thấy nhiều tài liệu về cách tạo khuôn mặt của chế độ xem bằng lưỡi dao và bộ điều khiển. Phương pháp nào là đúng hoặc tùy theo sở thích cá nhân?
Ví dụ: 1
Controller/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>
Ví dụ: 2
Controller/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
Quy ước và/hoặc lợi thế tốt nhất của những điều trên là gì?
Vui lòng sửa tôi nếu các ví dụ ở trên hoặc không đúng cách! – Mediabeastnz