简体   繁体   English

Laravel中的“在控制器上定义布局”是什么?

[英]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布局为ControllerViewLayout提供了两种不同的使用方式。 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM