Laravel:从控制器返回视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31613035/
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: Returning a view from a controller
提问by n0t_a_nUmb3R
I'm trying to learn how to use Laravel 5, but I've bumped into a problem. I've created the following code so far:
under app/HTTP/routes.php
:
我正在尝试学习如何使用 Laravel 5,但遇到了一个问题。到目前为止,我已经创建了以下代码:
在app/HTTP/routes.php
:
<?php
Route::get('/', 'MyController@home');
Created my own MyController.php
file under app\Http\Controllers
and added the following code to the controller:
在下面创建了我自己的MyController.php
文件app\Http\Controllers
并将以下代码添加到控制器中:
<?php
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
class MyController extends BaseController
{
public function home()
{
$name = "John Doe";
return View::make("index")->with("name", $name);
}
}
When I run the app I get the error:
当我运行应用程序时,出现错误:
FatalErrorException in MyController.php line 12:
Class 'App\Http\Controllers\View' not found
What am I doing wrong?
我究竟做错了什么?