Laravel 4:类不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24643955/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:47:44  来源:igfitidea点击:

Laravel 4: Class does not exist

phplaravellaravel-4

提问by PandaUser

I'm using Laravel v4.2 and getting the following error:

我正在使用 Laravel v4.2 并收到以下错误:

Class UserController does not exist

Here is my code:

这是我的代码:

user.php

用户名.php

class UserController extends BaseController {

    public function index(){
        return View::make('/')->with('title', 'Home | Public Review');
    }
}

routes.php

路由文件

Route::get( '/', array(
    'as' => 'index',
    'uses' => 'UserController@index'
) );

How do I resolve this error?

如何解决此错误?

回答by bishop

Typically, in Laravel 4, you'll find class UserControllerresiding in app/controllers/UserController.php.

通常,在 Laravel 4 中,您会发现class UserController驻留在app/controllers/UserController.php.

Laravel doesn't actually care, so long as the class in your routes.php can be auto-loaded. Consequently, always consider running php artisan dump-autoloadafter class name or class file name changes to ensure the autoloader is updated.

Laravel实际上并不关心,只要你的routes.php的类可以自动加载。因此,始终考虑php artisan dump-autoload在类名或类文件名更改后运行以确保自动加载器更新。

回答by rdgutierrez

Is because the correct is composer dump-autoload

是因为正确的是 composer dump-autoload