I’m trying to implement a third party library into a cakePHP 2.0 project.
I would like to use the PHP QR Code library to create QRCodes.
I made a new folder in app/Plugin called QrCode and put the library in the Vendor folder of my new plugin.
I created a component in Controller/Component called QrGeneratorComponent with this content:
<?php
App::import('Vendor', 'phpqrcode'.DS.'qrlib');
// Component defined in 'QrCode' plugin
class QrGeneratorComponent extends Component {
public function test() {
return QRcode::png('PHP QR Code :)');
}
}
In my application I added the component public $components = array('QrCode.QrGenerator'); and tried to access my test-method: $this->QrGenerator->test();
But I always get this error:
Fatal error: Class ‘QRcode’ not found in C:\xampp\htdocs\cake\app\Plugin\QrCode\Controller\Component\QrGeneratorComponent.php on line 8
So, what did I wrong? Is there a better way to implement a third party library?
I think you have to prefix the vendor path with the plugin name:
App::import('Vendor', 'QrCode.phpqrcode'.DS.'qrlib');