收益率没有显示

时间:2017-07-08 21:39:59

标签: laravel

我对如何在laravel上构建views文件夹有些怀疑。例如,我们在主页中有这种结构的博客网站:

标题(我们有一个菜单:主页链接,搜索栏搜索帖子,登录和登录按钮)

然后是最后5个帖子的部分。

然后是观看次数最多的部分。

然后是一个页脚。

我们如何根据观点构建此主页?例如,我们可以这样:

-views

  - layouts
    - header.blade.php
    - footer.blade.php
  - posts
     - lastposts.blade.php
     - mostviewed.blade.php
     - single.blade.php
  - layout.blade.php 
你觉得它还好吗?因为我测试这个并且它不起作用。例如,在layout.blade.php中,我有:

<!DOCTYPE html>
<html lang="en">
<head>
....
<link href="css/app.css" rel="stylesheet">
</head>

<body>

@include('layouts.nav')

@yield('lastposts')

@yield('mostviewed')

@include(layouts.footer')

</body>


</html>

当我正确访问页面时,我得到了页眉和页脚,但是@yields都没有显示任何内容。

在lastposts.blade.php中显示我拥有的最后5个帖子:

@extends('layout')
@section('lastposts')
<div>
   <h4>Title</h4>
    <p>Text</p>
  </div>
</div> 
<div>
   <h4>Title</h4>
    <p>Text</p>
  </div>
</div> 
<div>
   <h4>Title</h4>
    <p>Text</p>
  </div>
</div> 
<div>
   <h4>Title</h4>
    <p>Text</p>
  </div>
</div> 
<div>
   <h4>Title</h4>
    <p>Text</p>
  </div>
</div> 
@endsection

我对mostviewed.blade.php有相同的逻辑,但同样,@ yield('mostviewed')不显示任何内容。

你知道什么是不正确的吗?

路由文件:

Route::get('/', function () {
   return view('layout');
}

我有这条路线,因为我现在只有主页。

1 个答案:

答案 0 :(得分:1)

您创建了错误的视图。父视图是布局,它不了解大多数查看和最后一个帖子。这就是你编写@extends(&#39; layout&#39;)的原因,当你创建内容视图时,它会知道它必须从布局中扩展内容。

Route::get('/', function () {
   return view('posts.mostviewed');
}
相关问题