Laravel .blade 视图不会加载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29481768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel .blade view won't load
提问by Pastramifest
So I've been trying to learn laravel, but I've run into trouble pretty quickly and can't seem to find an answer to my problem. My routes.php file looks like
所以我一直在努力学习 Laravel,但我很快就遇到了麻烦,似乎无法找到我的问题的答案。我的 routes.php 文件看起来像
<?php
Route::get('/', 'PagesController@welcome');
Route::get('about', 'PagesController@about');
and PagesController.php looks like
和 PagesController.php 看起来像
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PagesController extends Controller {
public function welcome(){
return view('welcome');
}
public function about() {
$name = 'My name';
return view('about')->with('name', $name);
}
}
Finally, about.blade.php looks like this:
最后,about.blade.php 看起来像这样:
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>About Me: {{ $name }}</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</body>
</html>
When I try to load about about.blade.php nothing shows up in my web browser, and view page source reveals that there's no html there. But when I rename about.blade.php to about.php the file loads, except the {{ $name }}
part doesn't get rendered by blade like it should. The reason I'm especially confused is because welcome.blade.php, which is just the default welcome view for a new laravel project, loads just fine, as does the blade formatting stuff in it.
当我尝试加载 about.blade.php 时,我的 Web 浏览器中没有显示任何内容,并且查看页面源代码显示那里没有 html。但是,当我将 about.blade.php 重命名为 about.php 时,文件会加载,但该{{ $name }}
部分不会像应有的那样由刀片渲染。我特别困惑的原因是welcome.blade.php,它只是一个新的laravel项目的默认欢迎视图,加载得很好,其中的刀片格式内容也是如此。
回答by Deenadhayalan Manoharan
Try this..
尝试这个..
from
return view('welcome');
to
return View::make('welcome');
AND
From
return view('about')->with('name', $name);
to
return View::make('about')->with('name', $name);
回答by anchor
I had the same problem, also with about.blade.php file. When I renamed the file into abou.blade.php (without 't'), everything worked like expected. I tried several times more (with other words like ab.blade.php, abouts.blade.php,...) and i could not believe that the problem was the file naming (but it was). After couple of tests more, i found that the problem really was file permissions.
我有同样的问题,还有 about.blade.php 文件。当我将文件重命名为 abou.blade.php(没有 't')时,一切都按预期工作。我又试了几次(用其他词,如 ab.blade.php、abouts.blade.php、...),我不敢相信问题出在文件命名上(但确实如此)。经过多次测试,我发现问题确实出在文件权限上。
I work on Ubuntu and I saw that my permissions for /var/www/html folder were reset, so i needed to do 'chmod -R 777 /var/www/html/' once again.
我在 Ubuntu 上工作,我看到我对 /var/www/html 文件夹的权限被重置,所以我需要再次执行 'chmod -R 777 /var/www/html/'。
回答by Guilherme Cunha
Try return redirect('about')->with('name', $name);
尝试 return redirect('about')->with('name', $name);