【问题标题】:Using a third party lib with cakephp 2.0在 cakephp 2.0 中使用第三方库
【发布时间】: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-&gt;QrGenerator-&gt;test();

但我总是得到这个错误:

致命错误:第 8 行的 C:\xampp\htdocs\cake\app\Plugin\QrCode\Controller\Component\QrGeneratorComponent.php 中找不到类 'QRcode'

那么,我做错了什么?有没有更好的方法来实现第三方库?

【问题讨论】:

  • 最好使用Helper 而不是Component。因为它在View

标签: cakephp qr-code cakephp-2.0


【解决方案1】:

我认为您必须在供应商路径前加上插件名称:App::import('Vendor', 'QrCode.phpqrcode'.DS.'qrlib');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多