We want to use the FPDF library in one of our controllers.
We created the following files:
app
-Lib
--Fpdf
---files.php
---fpdf.php
---fdpf_wrapper.php <-- this is our class (FdpfWrapper) which extends the base FPDF class
Right before the controller class, we try this:
App::uses('FpdfWrapper', 'Lib/Fpdf');
But it fails every time. What are we doing wrong?
My case was a bit different.
To make
App::uses('ExampleAPI', 'ExampleAPI')
work make sure that:/Lib/ExampleAPI/ExampleAPI.php
exists and is readable/Lib/ExampleAPI/ExampleAPI.php
containsclass ExampleAPI{}
declarationnew ExampleAPI
in the referring codeFirst of all, package paths must be registered in order to be used with
App::uses
, andLib/Fpdf
is no such one, by default only the core packages are registered.You could either extend the paths for an already existing package, in your case that would be
Lib
:And then use
App::uses('FpdfWrapper', 'Lib');
http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#adding-paths-for-app-to-find-packages-in
or better add a new package:
http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#add-new-packages-to-an-application
Then you can use
App::uses('FpdfWrapper', 'Lib/Fpdf');
And last but not least, of course the filename must follow the CakePHP conventions as already mentioned by @Nunser, ie
fdpf_wrapper.php
must be renamed toFdpfWrapper.php