使用带有刀片模板引擎的流明5.2?

时间:2016-06-02 12:41:52

标签: laravel laravel-5.2 blade lumen lumen-5.2

我按照official documentation of laravel使用blade创建模板。我试图制作我的第一个模板,但不起作用。

1)存储在resources / views / default.blade.php --->

<html>
<head>
    @include('includes.head')
</head>
<body>
<div class="container">

    @include('includes.header')


    <div id="main" class="row">

            @yield('content')

    </div>

</div>
</body>
</html>

2)存储在resources / views / home.blade.php - &gt;

@extends('layouts.default')
@section('content')
    I am the Home Page!
@endsection

3)存储在boostrap / app.php中 - &gt;

$app->get('/', function (){
    return view('home');
});

4)localhost:8000 /返回此错误 - &gt;

哎呀,好像出了什么问题。 FileViewFinder.php第137行中的2/2 ErrorException:未找到视图[layouts.default]。 (查看:/home/vagrant/lumen/resources/views/home.blade.php)

in FileViewFinder.php line 137
at CompilerEngine->handleViewException(object(InvalidArgumentException), '1') in PhpEngine.php line 44
at PhpEngine->evaluatePath('/home/vagrant/lumen/storage/framework/views/96985f6d91158d600b1d1b64b5a3060d84415fda.php', array('__env' => object(Factory), 'app' => object(Application))) in CompilerEngine.php line 59
at CompilerEngine->get('/home/vagrant/lumen/resources/views/home.blade.php', array('__env' => object(Factory), 'app' => object(Application))) in View.php line 149
at View->getContents() in View.php line 120
at View->renderContents() in View.php line 85
at View->render() in Response.php line 53
at Response->setContent(object(View)) in Response.php line 199
at Response->__construct(object(View)) in RoutesRequests.php line 643
at Application->prepareResponse(object(View)) in RoutesRequests.php line 505
at Application->callActionOnArrayBasedRoute(array(true, array(object(Closure)), array())) in RoutesRequests.php line 479
at Application->handleFoundRoute(array(true, array(object(Closure)), array())) in RoutesRequests.php line 376
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request)) in CorsMiddleware.php line 6
at CorsMiddleware->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CorsMiddleware), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in RoutesRequests.php line 626
at Application->sendThroughPipeline(array('App\Http\Middleware\CorsMiddleware'), object(Closure)) in RoutesRequests.php line 382
at Application->dispatch(null) in RoutesRequests.php line 327
at Application->run() in index.php line 28
FileViewFinder.php第137行中的

1/2 InvalidArgumentException:未找到视图[layouts.default]。

in FileViewFinder.php line 137
at FileViewFinder->findInPaths('layouts.default', array('/home/vagrant/lumen/resources/views')) in FileViewFinder.php line 79
at FileViewFinder->find('layouts.default') in Factory.php line 165
at Factory->make('layouts.default', array('obLevel' => '1', '__env' => object(Factory), 'app' => object(Application))) in 96985f6d91158d600b1d1b64b5a3060d84415fda.php line 4
at include('/home/vagrant/lumen/storage/framework/views/96985f6d91158d600b1d1b64b5a3060d84415fda.php') in PhpEngine.php line 42
at PhpEngine->evaluatePath('/home/vagrant/lumen/storage/framework/views/96985f6d91158d600b1d1b64b5a3060d84415fda.php', array('__env' => object(Factory), 'app' => object(Application))) in CompilerEngine.php line 59
at CompilerEngine->get('/home/vagrant/lumen/resources/views/home.blade.php', array('__env' => object(Factory), 'app' => object(Application))) in View.php line 149
at View->getContents() in View.php line 120
at View->renderContents() in View.php line 85
at View->render() in Response.php line 53
at Response->setContent(object(View)) in Response.php line 199
at Response->__construct(object(View)) in RoutesRequests.php line 643
at Application->prepareResponse(object(View)) in RoutesRequests.php line 505
at Application->callActionOnArrayBasedRoute(array(true, array(object(Closure)), array())) in RoutesRequests.php line 479
at Application->handleFoundRoute(array(true, array(object(Closure)), array())) in RoutesRequests.php line 376
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request)) in CorsMiddleware.php line 6
at CorsMiddleware->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CorsMiddleware), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in RoutesRequests.php line 626
at Application->sendThroughPipeline(array('App\Http\Middleware\CorsMiddleware'), object(Closure)) in RoutesRequests.php line 382
at Application->dispatch(null) in RoutesRequests.php line 327
at Application->run() in index.php line 28

5 个答案:

答案 0 :(得分:4)

所选答案(https://stackoverflow.com/a/37625344/7506001)不正确。

@joeldg和@autista_z都是正确的。

截至Lumen 5.4,Blade视图仍然可用且可用,即使它们已不再记录。

完整示例:

SELECT C.*
FROM customer C
INNER JOIN salesman S ON C.salesman_id = S.salesman_id
  AND S.commission > 0.12
  AND S.city <> C.city;

答案 1 :(得分:3)

函数@extends(&#39; name&#39;)查找文件&#34; name.blade.php&#34;或&#34; name.php&#34;在目录&#34; resources / views&#34; 如果您使用@extends(&#39; layouts.default&#39;),则表示找到文件文件&#34; default.blade.php&#34;或&#34; default.php&#34;在目录&#34;资源/观点/布局&#34; (视图中的子文件夹布局)

但是你有&#34; deafault.blade.php&#34; in&#34; resources / views&#34; 所以应该通过 @extends(&#39;默认&#39;)

答案 2 :(得分:3)

你提到的URL是Laravel而不是Lumen,Lumen是一个轻量级的Laravel,它用于API层和后端作业处理。我推荐Laravel。

答案 3 :(得分:1)

选择的答案是错误的,Lumen默认安装了刀片。 你正在使用的回报不会起作用。

您的路线需要看起来像

$app->get('/', function () use ($app) {
  return $app->make('view')->make('index');
});

答案 4 :(得分:0)

我有同样的问题。这是因为文件夹/ var / www *受到保护。

您需要递归地将/ resource文件夹的CHMOD和CHOWN更改为您的流明项目。

试一试:     
$ cd /your-lumen-path
    $ sudo chmod 777 -R storage
    $ sudo chown -R $USER:$USER storage