我是laravel的新手,试图学习BLADE,但有一个问题让我感到震惊。 我有一个
index.blade.php
@layout('master')
我也有
master.blade.php
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Laravel: A Framework For Web Artisans</title>
<meta name="viewport" content="width=device-width">
</head>
<body>
hi from body
</body>
</html>
问题是,当我尝试调用index.blade.php时,它给了我一个 错误说
Unhandled Exception
Message:
View [master] doesn't exist.
Location:
C:\xampp\htdocs\laravel-laravel2\laravel\view.php on line 170
Stack Trace:
#0 C:\xampp\htdocs\laravel-laravel2\laravel\view.php(107): Laravel\View->path('master')
#1 C:\xampp\htdocs\laravel-laravel2\laravel\view.php(218): Laravel\View- >__construct('master', Array)
#2 C:\xampp\htdocs\laravel-laravel2\laravel\helpers.php(526): Laravel\View::make('master', Array)
#3 C:\xampp\htdocs\laravel-laravel2\laravel\view.php(386) : eval()'d code(2): view('master')
#4 C:\xampp\htdocs\laravel-laravel2\laravel\view.php(386): eval()
#5 C:\xampp\htdocs\laravel-laravel2\laravel\blade.php(71): Laravel\View->get()
#6 [internal function]: Laravel\Blade::Laravel\{closure}(Object(Laravel\View))
#7 C:\xampp\htdocs\laravel-laravel2\laravel\event.php(199): call_user_func_array(Object(Closure), Array)
#8 C:\xampp\htdocs\laravel-laravel2\laravel\event.php(138): Laravel\Event::fire('laravel.view.en...', Array, true)
#9 C:\xampp\htdocs\laravel-laravel2\laravel\view.php(348): Laravel\Event::until('laravel.view.en...', Array)
#10 C:\xampp\htdocs\laravel-laravel2\laravel\view.php(590): Laravel\View->render()
#11 C:\xampp\htdocs\laravel-laravel2\laravel\response.php(268): Laravel\View->__toString()
#12 C:\xampp\htdocs\laravel-laravel2\laravel\laravel.php(180): Laravel\Response->render()
#13 C:\xampp\htdocs\laravel-laravel2\public\index.php(34): require('C:\xampp\htdocs...')
#14 {main}
答案 0 :(得分:5)
我遇到了同样的问题。这可能是您的错误,也可能是您的环境。无论哪种方式,尝试这三件事:
将@layout('master')
放在php文件的顶部 - 没有白色
空间。
确保您的主视图标记为master.blade.php - 否 大写字母。
确保master.blade.php在application / views
注意:如果您将主视图放在其他文件夹中,例如application / views / some_folder调用它的正确方法是@layout('some_folder.master')
答案 1 :(得分:0)
使用 @extends('master')而不是@layout('master')