duancong7358 2014-01-26 16:05
浏览 382
已采纳

使用composer将Fpdf / Fpdi类添加到laravel时出现错误'class not found'

I'm trying to add the following two classes:

https://packagist.org/packages/itbz/fpdi
https://packagist.org/packages/itbz/fpdf

I've included them in my composer.json file:

"require-dev": {
        "itbz/fpdi": "dev-master",
        "itbz/fpdf": "1.7.2"
    }

When I try to reference them in my app/config/app.php file like so:

'providers' => array (
    .....
    'itbz\fpdf',
    'itbz\fpdi',
),

'aliases' => array (
    .....
    'Fpdf'            => 'itbz\fpdf\Facades\Fpdf',
    'Fpdi'            => 'itbz\fpdi\Facades\Fpdi',

),

I get a 'class not found' error when I run composer install for both.

I've done composer update after I've included the require-dev information in composer.json, so I believe the errors are in my referencing of the two classes in app/config/app.php. I don't know how to reference them, so if someone is able to help that would be great.

  • 写回答

1条回答 默认 最新

  • dongpu1879 2014-01-26 16:23
    关注

    Have you done a rebuild of your autoloads?

    composer dump-autoload
    

    After that is done, I believe you should be able to just use the classes without use first.

    EDIT: I don't know these packages but I am not sure they include the Facade classes you mention. Facades are very specific to Laravel 4.

    I believe if you remove the aliases then this should work OK:

    'Fpdf'            => 'itbz\fpdf\Facades\Fpdf',
    'Fpdi'            => 'itbz\fpdi\Facades\Fpdi',
    

    if you want to then use these classes in your app, you would say:

    $fpdi = new \fpdi\FPDI();
    $fpdf = new \fpdf\FPDF();
    

    or something like that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?