laravel 将 lumen 5.2 与刀片模板引擎一起使用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37592197/
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
using lumen 5.2 with blade template engine?
提问by Richard Ortiz
I follow the official documentation of laravelto create templates with blade.I'm trying to make my first template but doesn't work.
我按照laravel的官方文档使用刀片创建模板。我正在尝试制作我的第一个模板但不起作用。
1)Stored in resources/views/default.blade.php --->
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)stored in resources/views/home.blade.php -->
2)存储在resources/views/home.blade.php -->
@extends('layouts.default')
@section('content')
I am the Home Page!
@endsection
3)Stored in boostrap/app.php -->
3)存储在boostrap/app.php -->
$app->get('/', function (){
return view('home');
});
4) localhost:8000/ return this error -->
4) localhost:8000/ 返回这个错误 -->
Whoops, looks like something went wrong. 2/2 ErrorException in FileViewFinder.php line 137: View [layouts.default] not found. (View: /home/vagrant/lumen/resources/views/home.blade.php)
哎呀,看起来出事了。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
1/2 InvalidArgumentException in FileViewFinder.php line 137: View [layouts.default] not found.
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
回答by jpoesen
The selected answer (https://stackoverflow.com/a/37625344/7506001) is incorrect.
所选答案 ( https://stackoverflow.com/a/37625344/7506001) 不正确。
@joeldg and @autista_z are both correct.
@joeldg 和 @autista_z 都是正确的。
As of Lumen 5.4, Blade views are still available and usable, even though they're no longer documented.
从 Lumen 5.4 开始,Blade 视图仍然可用且可用,即使它们不再被记录。
Full example:
完整示例:
// In routes/web.php:
$app->get('/', function () use ($app) {
return $app->make('view')->make('home');
});
// In resources/views/default.blade.php:
<html>
<head>...</head>
<body>
<div id="whatever">
@yield('content')
</div>
</body>
</html>
// In resources/views/home.blade.php:
@extends('default')
@section('content')
<p>I am the Home Page!</p>
@endsection
回答by Autista_z
Function @extends('name') find file "name.blade.php" or "name.php" in the directory "resources/views" If you use @extends('layouts.default'), it means, it find file file "default.blade.php" or "default.php" in directory "resources/views/layouts" (subfolder layouts in views)
函数@extends('name') 在"resources/views" 目录下查找文件"name.blade.php" 或"name.php" 如果使用@extends('layouts.default'),则表示查找文件目录“resources/views/layouts”中的文件“default.blade.php”或“default.php”(视图中的子文件夹布局)
But you have your "deafault.blade.php" in "resources/views" So it should by @extends('default')
但是你在“资源/视图”中有你的“deafault.blade.php”所以它应该由@extends('default')
回答by Khesayed
The URL you mention is for Laravel not Lumen, Lumen is a lightweight Laravel, It's for API layer and backend job processing. I recommend Laravel instead.
您提到的 URL 是针对 Laravel 而不是 Lumen,Lumen 是轻量级 Laravel,用于 API 层和后端作业处理。我推荐 Laravel。
回答by joeldg
The selected answer is wrong, Lumen has blade installed by default. The return you are using won't work.
选择的答案是错误的,Lumen 默认安装了刀片。您正在使用的回报将不起作用。
Your route needs to look like
你的路线需要看起来像
$app->get('/', function () use ($app) {
return $app->make('view')->make('index');
});
回答by Felipe Barreiros
I had same problem. It happen because folder /var/www* is protected.
我有同样的问题。这是因为文件夹 /var/www* 受到保护。
You need to change CHMOD and CHOWN of /resource folder, into your lumen project, recursively.
您需要将 /resource 文件夹的 CHMOD 和 CHOWN 递归更改到您的 lumen 项目中。
Try it:
$ cd /your-lumen-path
$ sudo chmod 777 -R storage
$ sudo chown -R $USER:$USER storage
尝试一下:
$ cd /your-lumen-path
$ sudo chmod 777 -R storage
$ sudo chown -R $USER:$USER storage