php Laravel 视图未找到异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17913929/
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 view not found exception
提问by Dean Chiu
I have problem with laravel view is not found by route function I did composer dumpautoload but no use ArticleController.php
我有路由功能找不到laravel视图的问题我做了composer dumpautoload但没有使用ArticleController.php
<?php
class ArticleController extends BaseController
{
public function showIndex()
{
return View::make('index');
}
public function showSingle($articleId)
{
return View::make('single');
}
}
//Route
Route::get('index', 'ArticleController@showIndex');
InvalidArgumentException
无效参数异常
View [index] not found.
open: /opt/lampp/htdocs/laravel-project/bootstrap/compiled.php
foreach ((array) $paths as $path) {
foreach ($this->getPossibleViewFiles($name) as $file) {
if ($this->files->exists($viewPath = $path . '/' . $file)) {
return $viewPath;
}
}
}
throw new \InvalidArgumentException("View [{$name}] not found.");
}
protected function getPossibleViewFiles($name)
Server/Request Data
REDIRECT_UNIQUE_ID UfWlAn8AAQEAABR2VakAAAAF
REDIRECT_STATUS 200
UNIQUE_ID UfWlAn8AAQEAABR2VakAAAAF
HTTP_HOST localhost
HTTP_USER_AGENT Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0
HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_LANGUAGE en-US,en;q=0.5
HTTP_ACCEPT_ENCODING gzip, deflate
HTTP_COOKIE laravel_session=f94fpel78jn89nhah32mflqn15
HTTP_CONNECTION keep-alive
HTTP_CACHE_CONTROL max-age=0
PATH /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
LD_LIBRARY_PATH /opt/lampp/lib:/opt/lampp/lib
SERVER_SIGNATURE
SERVER_SOFTWARE Apache/2.4.4 (Unix) OpenSSL/1.0.1e PHP/5.4.16 mod_perl/2.0.8-dev Perl/v5.16.3
SERVER_NAME localhost
SERVER_ADDR 127.0.0.1
SERVER_PORT 80
REMOTE_ADDR 127.0.0.1
DOCUMENT_ROOT /opt/lampp/htdocs
REQUEST_SCHEME http
CONTEXT_PREFIX
CONTEXT_DOCUMENT_ROOT /opt/lampp/htdocs
SERVER_ADMIN [email protected]
SCRIPT_FILENAME /opt/lampp/htdocs/laravel-project/public/index.php
REMOTE_PORT 50211
REDIRECT_URL /laravel-project/public/index
GATEWAY_INTERFACE CGI/1.1
SERVER_PROTOCOL HTTP/1.1
REQUEST_METHOD GET
QUERY_STRING
REQUEST_URI /laravel-project/public/index
SCRIPT_NAME /laravel-project/public/index.php
PHP_SELF /laravel-project/public/index.php
REQUEST_TIME_FLOAT 1375053058.123
REQUEST_TIME 1375053058
采纳答案by Rubens Mariuzzo
This happens when Laravel doesn't find a view file in your application. Make sure you have a file named: index.php
or index.blade.php
under your app/views
directory.
当 Laravel 在您的应用程序中找不到视图文件时,就会发生这种情况。确保您有一个名为:index.php
或index.blade.php
在您的app/views
目录下的文件。
Note that Laravel will do the following when calling View::make
:
请注意,Laravel 在调用时会执行以下操作View::make
:
- For
View::make('index')
Laravel will look for the file:app/views/index.php
. - For
View::make('index.foo')
Laravel will look for the file:app/views/index/foo.php
.
- 对于
View::make('index')
Laravel 将查找文件:app/views/index.php
. - 对于
View::make('index.foo')
Laravel 将查找文件:app/views/index/foo.php
.
The file can have any of those two extensions: .php
or .blade.php
.
该文件可以具有这两个扩展名中的任何一个:.php
或.blade.php
.
回答by Dean Chiu
This error also occurs when you try to move the whole project directory to other path. And you happened to run the following commands below BEFORE you move.
当您尝试将整个项目目录移动到其他路径时,也会发生此错误。在您移动之前,您碰巧在下面运行了以下命令。
php artisan optimize --force
php artisan config:cache
php artisan route:cache
Mine error message shows like this
As you can see the old path was written in the compiled.php. So, to fix the problem. Simply run the same command AGAIN under the project folder in your new folder location.
正如你所看到的,旧路径写在compiled.php 中。所以,要解决问题。只需在新文件夹位置的项目文件夹下再次运行相同的命令。
php artisan optimize --force
php artisan config:cache
php artisan route:cache
Hope this helps.
希望这可以帮助。
回答by Amir
This command works for me
这个命令对我有用
php artisan config:cache
As Laravel doc says that by default, Laravel is configured to use the file cache driver, which stores the serialized, cached objects in the filesystem. So it needs to recache the file system so that newly added views and route are available to show. I also not sure why laravel needs to recache actually
正如 Laravel 文档所说,默认情况下,Laravel 被配置为使用文件缓存驱动程序,它将序列化的缓存对象存储在文件系统中。所以它需要重新缓存文件系统,以便新添加的视图和路由可以显示。我也不知道为什么 Laravel 实际上需要重新缓存
回答by Inamur Rahman
This might be possiblethat your view is present even though it shows the error. So to solve this issue you need to stop the server and run this command on the terminal.
即使您的视图显示错误,也可能存在您的视图。因此,要解决此问题,您需要停止服务器并在终端上运行此命令。
php artisan config:cache
then restart the server
然后重启服务器
回答by Paspartu
Just in the controller call
只是在控制器调用中
return View('index');
without
没有
::make
回答by Adam
In my case I was calling View::make('User/index')
, where in fact my view was in user directory and it was called index.blade.php. Ergo after I changed it to View@make('user.index')
all started working.
在我的例子中,我正在调用View::make('User/index')
,实际上我的视图在用户目录中,它被称为 index.blade.php。Ergo 在我将其更改为View@make('user.index')
全部后开始工作。
回答by ndarriulat
I was having the same error, but in my case the view was called seeProposal
.
我遇到了同样的错误,但在我的情况下,视图被称为seeProposal
.
I changed it to seeproposal
and it worked fine...
我把它改成了seeproposal
,它工作得很好......
It was not being an issue while testing locally, but apparently Laravel makes a distinction with capital letters running in production. So for those who have views with capital letters, I would change all of them to lowercase.
在本地测试时这不是问题,但显然 Laravel 对生产中运行的大写字母进行了区分。所以对于那些对大写字母有意见的人,我会将它们全部更改为小写。
回答by jeff-h
Somewhat embarrassingly, I discovered another rather trivial cause for this error: I had a full stop in the filename of my blade file (eg resources/views/pages/user.invitation.blade.php
). It really did make sense at the time!
有点尴尬的是,我发现了这个错误的另一个相当微不足道的原因:我的刀片文件的文件名中有句号(例如resources/views/pages/user.invitation.blade.php
)。当时真的觉得很有道理!
I was trying to reference it like so: view('pages.user.invitation')
我试图像这样引用它: view('pages.user.invitation')
but of course Laravel was looking for the file at resources/views/pages/user/invitation.blade.php
and throwing the view not found
.
但当然 Laravel 正在寻找该文件resources/views/pages/user/invitation.blade.php
并将view not found
.
Hope this helps someone.
希望这可以帮助某人。
回答by Eduin Morales
Create the index.blade.php file in the views folder, that should be all
在views文件夹中创建index.blade.php文件,应该是全部
回答by Ricky Orlando Napitupulu
check your blade syntax on the view that said not found i just fix mine
检查您的刀片语法,该视图显示未找到我只是修复了我的
@if
@component
@endif
@endcomponent
to
到
@if
@component
@endcomponent
@endif