0

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.

a7omiton
  • 1,597
  • 4
  • 34
  • 61

1 Answers1

1

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.

warspite
  • 622
  • 3
  • 12
  • it rebuilds the class autoloader so that when you use one of the classes in your app you don't have to load it first. That is what you are doing when you add packages to the `providers` array. You are making them part of the Laravel autoload. But you must run the `composer dump-autload' when you do this so that the autloader is rebuilt with your new packages added. – warspite Jan 26 '14 at 16:28
  • Oh, I never had to do that with a previous package I tried out (http://stackoverflow.com/questions/19319198/install-fpdf-on-laravel-4). I'm also not including the two classes in the 'autoload' index in composer.json, it's in one that I created 'require-dev' – a7omiton Jan 26 '14 at 16:38
  • Check out my edit above. The errors likely have todo with your alias classes not existing – warspite Jan 26 '14 at 16:54
  • Yes you're right, I had no need to add the two classes to the providers and aliases array and just had to namespace them. I was under the impression that you had to do so? If I want to create an alias for the class, would that remove the need to call the class like '\fpdi\FPDI()'? Thank you :) – a7omiton Jan 26 '14 at 17:01
  • 1
    in Laravel, you add classes to the `provider` array so that you can take advantage of the Laravel configured autoloader. It is not needed if you already are autoloading your classes in some other way in the `autoload` section of your `composer.json` such as `psr-0`. As for the `alias` array, you can still use Laravel for this, I believe by something like: `'fpdi' => 'fpdi\FPDI',` – warspite Jan 26 '14 at 17:14