[英]what is “Defining A Layout On A Controller” in Laravel?
what is "Defining A Layout On A Controller" in Laravel? 什么是Laravel中的“在控制器上定义布局”? For example this code :
例如下面的代码:
$this->layout->content = View::make('user.profile');
What does this mean?: 这是什么意思?:
$this->layout->content
I have read the documentation but I didn't understand it. 我已经阅读了文档,但我听不懂。
Laravel
gives us two different ways to use a Layout
, in the Controller
and also in the View
by extending the master/main
layout. Laravel
通过扩展master/main
布局为Controller
和View
的Layout
提供了两种不同的使用方式。 So, defining a layout in the controller looks like this: 因此,在控制器中定义布局如下所示:
class UserController extends BaseController {
// The master layout in the layouts folder
protected $layout = 'layouts.master';
public function showProfile()
{
// Set the content to the master layout to display
$this->layout->content = View::make('user.profile');
}
}
So, a layout is a template
where the content generated by a view will be presented within that layout. 因此,布局是一个
template
,其中视图生成的内容将在该布局内显示。 On the other hand, you can use a layout
directly from the view and in this case you don't need to define a layout in the controller. 另一方面,您可以直接从视图中使用
layout
,在这种情况下,您无需在控制器中定义布局。 A view will extend the master layout like this: 视图将扩展主布局,如下所示:
@extends('layouts.master')
@section('sidebar')
<p>This is appended to the master sidebar.</p>
@stop
The master layout may look like this: 主布局可能如下所示:
<html>
<body>
@section('sidebar')
This is the master sidebar.
@show
<div class="container">
@yield('content')
</div>
</body>
</html>
Read more on the Laravel website . 在Laravel网站上阅读更多内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.