【问题标题】:PHPLaravel: How do I display a ViewPHPLaravel:如何显示视图
【发布时间】:2016-03-31 13:09:22
【问题描述】:

我正在尝试显示具有以下代码的视图:

{!! Stored in /resources/views/about.blade.php !!}
@extends('layouts.app')
@section('title')
Conway's Game Of Life - About
@endsection

@section('content')
<h2>Conway's Game Of Life - About</h2>

<p>The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.</p>
@endsection

然后是以下主刀片页面:
<!-- Stored in /resources/views/layouts/app.blade.php --> <title>@yield('title')</title>
@yield('content')

在这之后会出现一个 routes.php:

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

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

Route::get('/about/', 'HomeController@About');

我收到以下错误:

`FileViewFinder.php 第 137 行中的 InvalidArgumentException:

View [index.blade] not found. ErrorException in FileViewFinder.php line 137:

未找到视图 [index.blade]。 (查看:C:\Bitnami\wampstack-5.5.30-0\apache2\htdocs\GameOfLife\resources\views\layouts\app.blade.php) ErrorException 在 FileViewFinder.php 第 137 行:

未找到视图 [index.blade]。 (查看:C:\Bitnami\wampstack-5.5.30-0\apache2\htdocs\GameOfLife\resources\views\layouts\app.blade.php) (查看:C:\Bitnami\wampstack-5.5.30-0\ apache2\htdocs\GameOfLife\resources\views\layouts\app.blade.php)`

我应该怎么做才能避免出错?

谢谢你帮我摆脱困境!

PS,建议:
以下答案均未找到问题的解决方案。这可能是我使用 PHP7,而不是任何较小的版本吗?它可能会影响 Laravel 程序代码的执行。

【问题讨论】:

    标签: php laravel view


    【解决方案1】:

    首先确保在layouts 文件夹下app.blade.php 存在并且它在正文中有@yield('content') 这两个语句,在head 标签之间有@yield('title')
    做其中之一,而不是两者都做

    Route::get('about', function () {
         return view('about');
    });
    OR
    Route::get('about', 'HomeController@About');
    


    并确保您的index.blade.php 存在于views

    如果仍然有错误,请发表评论。

    【讨论】:

      【解决方案2】:

      您有名为 about.blade.php 的视图,但缺少名为 index.blade.php 的视图,因为您定义了该路由,所以这是预期的

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

      此外,由于您使用的是布局模板,因此在所有视图之上,您必须使用 @extend 指定要扩展的视图

      https://laravel.com/docs/5.1/blade#extending-a-layout

      【讨论】:

        猜你喜欢
        • 2014-08-04
        • 2011-04-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多