【发布时间】:2011-12-30 11:07:50
【问题描述】:
我正在尝试在 cakePHP 2.0 项目中实现第三方库。 我想使用PHP QR Code 库来创建二维码。
我在app/Plugin 中创建了一个名为QrCode 的新文件夹,并将库放在我的新插件的Vendor 文件夹中。
我在Controller/Component 中创建了一个名为QrGeneratorComponent 的组件,其中包含以下内容:
<?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 :)');
}
}
在我的应用程序中,我添加了组件public $components = array('QrCode.QrGenerator'); 并尝试访问我的测试方法:$this->QrGenerator->test();
但我总是得到这个错误:
致命错误:第 8 行的 C:\xampp\htdocs\cake\app\Plugin\QrCode\Controller\Component\QrGeneratorComponent.php 中找不到类 'QRcode'
那么,我做错了什么?有没有更好的方法来实现第三方库?
【问题讨论】:
-
最好使用
Helper而不是Component。因为它在View
标签: cakephp qr-code cakephp-2.0