简单的 Laravel View::make() 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28893055/
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
simple Laravel View::make() not working
提问by Ryan DuShane
So I'm learning some basic Laravel stuff as I am new to PHP.
I am following a basic tutorial that is having me print stuff to a file named home.blade.php
.
所以我正在学习一些基本的 Laravel 东西,因为我是 PHP 的新手。我正在学习一个基本教程,该教程让我将内容打印到名为home.blade.php
.
The way I am calling it now is as follows.
我现在调用它的方式如下。
Here is my routes.php
这是我的 routes.php
Route::get('/', array(
'as' => 'home',
'uses' => 'HomeController@home'
));
Here is my HomeController.php
这是我的 HomeController.php
class HomeController extends Controller {
public function home() {
return View::make('home');
}
}
Here is home.blade.php
这是 home.blade.php
{{'Hello.'}}
Before you ask, yes my home.blade.php is inside of my Views folder.
在你问之前,是的,我的 home.blade.php 在我的 Views 文件夹中。
The error print out is as follows
错误打印出来如下
FatalErrorException in HomeController.php line 6:
Class 'App\Http\Controllers\View' not found
in HomeController.php line 6
at HandleExceptions->fatalExceptionFromError(array('type' => '1', 'message' => 'Class 'App\Http\Controllers\View' not found', 'file' => '/Users/ryandushane/Google Drive/Web_WorkSpace/theNeonSurf/app/Http/Controllers/HomeController.php', 'line' => '6')) in compiled.php line 1738
at HandleExceptions->handleShutdown()
Here's the odd part. If I change my routes.php
to simply contain
这是奇怪的部分。如果我将我更改routes.php
为简单地包含
Route::get('/', function()
{
return View::make('home');
});
it functions fine.
它运行良好。
Does anyone have an idea of what I could do?
有没有人知道我能做什么?
回答by mininoz
New syntax for Laravel 5
Laravel 5 的新语法
public function home() {
return view('home');
}
For more information you can read it from here http://laravel.com/docs/5.0/views
有关更多信息,您可以从这里阅读http://laravel.com/docs/5.0/views
回答by Raham
Try this in your top of the class(controller)
在您的班级(控制器)中尝试此操作
use View;
回答by kylehyde215
I bet your controller class has a namespace, yes? Try \View::make('home');
Or you can import it in the top of the file:
我敢打赌你的控制器类有一个命名空间,是吗?试试\View::make('home');
或者你可以在文件顶部导入:
<?php
namespace App\Http\Controllers;
use View;
class HomeController extends Controller {
public function home() {
return View::make('home');
}
}