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/"
        },
        ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用