简体   繁体   English

Laravel .blade视图将无法加载

[英]Laravel .blade view won't load

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. 所以我一直在尝试学习laravel,但是我很快就遇到了麻烦,似乎无法找到解决我问题的答案。 My routes.php file looks like 我的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. 当我尝试加载about.blade.php时,我的网络浏览器中没有任何显示,并且查看页面的源代码表明那里没有html。 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. 但是,当我将about.blade.php重命名为about.php时,文件加载,除了{{ $name }}部分不会像它应该的那样被刀片渲染。 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. 我特别困惑的原因是,welcome.blade.php只是一个新的laravel项目的默认欢迎视图,它的加载方式还不错,刀片中的格式化内容也是如此。

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); 

I had the same problem, also with about.blade.php file. 我也有关于about.blade.php的问题。 When I renamed the file into abou.blade.php (without 't'), everything worked like expected. 当我将文件重命名为abou.blade.php(不带“ t”)时,一切都按预期工作。 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). 我尝试了几次(使用ab.blade.php,abouts.blade.php等其他词),但我不敢相信问题出在文件命名(但确实是)。 After couple of tests more, i found that the problem really was file permissions. 经过多次测试后,我发现问题确实出在文件权限上。

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 /”。

尝试return redirect('about')->with('name', $name);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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