类App/Http/Controllers/View找不到错误 [英] Class App/Http/Controllers/View Not Found error
问题描述
我是laravel 5的新手,目前被此错误困扰:
I am new to laravel 5 and currently stumped by this error:
FatalErrorException in TicketController.php line 18: Class 'App\Http\Controllers\View' not found
奇怪的是,该视图实际上确实存在,我检查了路由是否确实在路由至正确的控制器,并且确实如此,当我尝试执行此操作时会弹出错误:
Weird thing is the view does in fact exist, i checked to see if the route was indeed routing to the right controller and it was, the error pops up when i try to do this:
return View::make('tickets.bus.index');
要么是我在某个地方犯了一些错误,要么是实现方式与laravel 4不同
It's either i am making some mistake somewhere or if the implementation is different from laravel 4
推荐答案
问题不是实际视图,而是 class View
.您会看到,当您仅引用View::make('tickets.bus.index')
之类的类时,PHP就会在您的当前名称空间中搜索该类.
The problem is not the actual view but the class View
. You see when you just reference a class like View::make('tickets.bus.index')
PHP searches for the class in your current namespace.
在这种情况下为App\Http\Controllers
.但是,View
类显然不存在于控制器的命名空间中,而是存在于Laravel框架命名空间中.它也有一个别名,该别名位于 global 命名空间中.
In this case that's App\Http\Controllers
. However the View
class obviously doesn't exists in your namespace for controllers but rather in the Laravel framework namespace. It has also an alias that's in the global namespace.
您可以通过在反斜杠前面加一个反斜杠来引用别名:
You can either reference the alias in the root namespace by prepending a backslash:
return \View::make('tickets.bus.index');
或在顶部添加导入语句:
Or add an import statement at the top:
use View;
这篇关于类App/Http/Controllers/View找不到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!