laravel blade @include not working(laravel 刀片 @include 不工作)
问题描述
我正在尝试使用刀片语法在我的主页中包含文件:-
I am trying to include files in my homepage using blade syntax :-
@foreach($data as $articles)
@include(app_path().$articles->path)
<br />
@endforeach
这不起作用.
错误提示:-
View [/var/www/blogproject/project/app/pages/articles/first-post.php] not found
我什至尝试只包含第一页:-
I even tried including just the first page :-
@include(app_path().'/pages/articles/first-post.php')
但正常的 php 包含工作正常:-
But the normal php include is working fine :-
<?php include(app_path().'/pages/articles/first-post.php'); ?>
请帮忙
推荐答案
那是因为该文件不在 app/views 目录中.当您调用 @include('filename') 时,Blade 会自动在 apps/views 目录中查找任何具有该名称的文件.此外,您不应该编写文件扩展名,因为 Blade 会自动查找具有 .blade.php 和 .php 扩展名的文件.
That's because that file is not in the app/views directory. When you call @include('filename'), Blade automatically looks for any file with that name, inside the apps/views directory. Also, you're not supposed to write the file extension, as Blade automatically looks for files with .blade.php and .php extensions.
如果您想在 @include 标记上使用其他目录中的文件,请将目录添加到 app/config/view.php 上的路径数组中.在你的情况下,它会是这样的:
If you want to use files from other directories on the @include tag, add the directory to the paths array, on app/config/view.php. In your case, it'd be something like this:
app/config/view.php
<?php
// ...
'paths' => array(
__DIR__.'/../views',
__DIR__.'/../pages'
);
然后,你会在 Blade 上这样称呼它:
Then, you'd call it on blade like so:
@include('articles/first-post')
这篇关于laravel 刀片 @include 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:laravel 刀片 @include 不工作
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
