php - 如何在 Laravel 中以正确的方式设置路由、 Controller 和 View ?

标签 php laravel laravel-5 namespaces

我刚开始玩 laravel。首先,这是我遇到的最好的框架。现在这是我的问题。我试图从路由指向 -> Controller -> View

//This is my Controller file

 public function index()
{
    return View::make('pages', array('name' => 'Taylor'));
}

 // This is my Routes File
Route::get('/', 'pagesController@index');

View file => pages.blade.php

这是我得到的错误。
FatalErrorException in pagesController.php line 19:
Class 'App\Http\Controllers\View' not found

最佳答案

从错误看来,问题在于 View在当前命名空间中找不到类。

试试这个方法:

//use the View class from the global namespace
return \View::make('pages', array('name' => 'Taylor'));

或导入 View Controller 脚本开头的类:
use View;

关于php - 如何在 Laravel 中以正确的方式设置路由、 Controller 和 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31493794/

相关文章:

拉维尔 : Group users by month and output month name

php - 在 macOS 上为 xampp 安装 mongodb 扩展

jquery - Socket.IO类型错误: Cannot read property 'broadcast' of undefined

php - Woocommerce Storefront template-tags.php 更改为 storefront_cart_link() 不可能

php - 在 Laravel 中成功注册后如何重定向到上一页?

拉拉维尔。使用查询生成器获取表的单列值

php - 如何从一条 laravel 路由获取返回值到另一条路由

php - 使用参数创建 [Laravel 5.2]

PHP-fputcsv : put JSON values retrieved from MySQL field in separate columns

php - 如何在 Eloquent ORM 中创建 isAuthorized() 方法?