dongpo2002 2014-10-21 18:57
浏览 52
已采纳

Laravel 4自定义身份验证提供程序 - 找不到类错误

I am trying to implement a custom auth provider by following this guide: http://laravel-recipes.com/recipes/115/using-your-own-authentication-driver

In my project, I have created the following file:

app/Latheesan/Extensions/DummyAuthProvider.php

with the sample code from Step #1 and renamed "MyApp" to "Latheesan".

I then went to add the following line in my app/start/global.php

Auth::extend('dummy', function($app) {
    return new Latheesan\Extensions\DummyAuthProvider;
});

Then updated the app/auth/config.php and changed the driver like so:

'driver' => 'dummy',

Finally I amended my routes.php like this:

Route::filter('auth', function($route, $request) {
    if (Auth::guest())
        return Redirect::guest('login');
});

Route::get('login',  array('uses' => 'HomeController@showLogin'));
Route::post('login', array('uses' => 'HomeController@doLogin'));
Route::get('logout', array('uses' => 'HomeController@doLogout'));

Route::get('/', function() {
    return View::make('hello');
})->before('auth');

Before I tested my code, I ran the composer dump-auto to generate autoload files.

When I visited my test site: http://laravel-test.local I am getting this error:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR) Class 'Latheesan\Extensions\DummyAuthProvider' not found

Any idea why my custom auth provider class isn't loading?

  • 写回答

1条回答 默认 最新

  • dongqian9013 2014-10-21 20:03
    关注

    By default composer doesn't know how to autoload your new class, so you would need to add an PSR rule in the autoload section of your composer.json file. This should do the trick:

    "autoload": {
        "psr-0": {
            "Latheesan": "app/"
        },
        ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况