php CodeIgniter 第三方类未加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21016626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:44:44  来源:igfitidea点击:

CodeIgniter Third party class not loading

phpcodeigniter

提问by Code Lover

I am trying to implement Dashboard widget class (found here: http://harpanet.com/programming/php/codeigniter/dashboard/index#installation) but it is giving me error Unable to load the requested class

我正在尝试实现仪表板小部件类(在这里找到:http: //harpanet.com/programming/php/codeigniter/dashboard/index#installation)但它给了我错误Unable to load the requested class

I have tried to add this class in autoload as well as menually to my controller $this->load->library('dash')but this also giving the same error.

我试图在自动加载中以及从菜单中将这个类添加到我的控制器中,$this->load->library('dash')但这也给出了同样的错误。

I have checked dash.phpand found below method private function __example__()but can't understand what the developer is saying in comment.

我已检查dash.php并找到以下方法,private function __example__()但无法理解开发人员在评论中所说的内容。

class Dash
{
    private function __example__()
    {
        /*
         * This function is purely to show an example of a dashboard method to place
         * within your own controller.
         */

        // load third_party hArpanet dashboard library
        $this->load->add_package_path(APPPATH.'third_party/hArpanet/hDash/');
        $dash =& $this->load->library('dash');
        $this->load->remove_package_path(APPPATH.'third_party/hArpanet/hDash/');

        // configure dashboard widgets - format: type, src, title, cols, alt (for images)
        $dash->widgets = array(

                    array('type'=>'oop',     'src'=>'test_dash',         'title'=>'Test OOP Widget',    'cols'=>3),

                    // if 'title' is set to FALSE, the title block is omitted entirely
                    // note: this is an 'html' widget but is being fed content from a local method
                    array('type'=>'html',     'src'=>self::test_method(), 'title'=>false,    'cols'=>3),

                    array('type'=>'file',     'src'=>'saf_inv.htm',         'title'=>'Safety Investigation'),

                    // multi-content widget - set widget title in outer array (also note use of CI anchor to create a link)
                    array('title'=>anchor('tz', 'TARGET ZERO'),
                            // sub-content follows same array format as single content widget
                            // 'img' content can also have an 'alt' text
                            array('type'=>'img',    'src'=>'saf_tzout.gif',      'alt'=>'Action Completed'),
                            array('type'=>'file',    'src'=>'saf_tz.htm'),
                            array('type'=>'file',    'src'=>'ave_close.htm',     'title'=>'Average Time to Close')
                            ),

                    array('type'=>'file',    'src'=>'saf_meet.htm',        'title'=>'Safety Meeting'),
                    array('type'=>'file',    'src'=>'saf_acc.htm',        'title'=>'Accident Investigation'),
                    array('type'=>'file',    'src'=>'saf_hazmat.htm',     'title'=>anchor('hazmat', 'HAZMAT')),
                    array('type'=>'file',    'src'=>'saf_cont.htm',         'title'=>'Loss of Containment'),
                    array('type'=>'file',    'src'=>'saf_worksinfo.htm',    'title'=>'Works Information'),

                    // an action widget - 'clear' will generate a blank widget with a style of clear:both
                    array('type'=>'clear'),

                    // multi-content widget - width can be set using the 'cols' param in outer array
                    array('title'=>'RAG Report', 'cols' => 2,

                            array('type'=>'file',    'src'=>'saf_rag.htm'),
                            array('type'=>'img',    'src'=>'ProcSaf.gif')),

                    array('type'=>'file',    'src'=>'saf_chrom.htm',        'title'=>'Chrome checks'),
                );

        // populate the view variable
        $widgets = $dash->build('safety');

        // render the dashboard
        $this->load->view('layout_default', $widgets);

    }
...................

} // end of Dash class

Installation path isroot/application/third_party/hArpanet/hDash/libraries/dash.php

安装路径是root/application/third_party/hArpanet/hDash/libraries/dash.php

How can I load this class to my system and use widgets?

如何将此类加载到我的系统并使用小部件?

回答by ReNiSh A R

You have to create a library that initialize the third party class:

您必须创建一个初始化第三方类的库:

for Eg:

例如:

--in library create a file named mydash.php--

-- 在库中创建一个名为mydash.php的文件--

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MyDash
{
    public function __construct()
    {
        require_once APPPATH.'third_party/hArpanet/hDash/libraries/dash.php';
    }
}

load the library using:

使用以下方法加载库:

$this->load->library('mydash');

then you are able to use the Dash class. Also able to load library in autoload.

然后你就可以使用 Dash 类了。也能够在自动加载中加载库。

Thank you...

谢谢...

回答by Stackman

Sorry to hear you were having problems, (I've only just noticed this SO entry). Thanks to ReNiSh for his workaround, much appreciated.

很抱歉听到您遇到问题,(我刚刚注意到这个 SO 条目)。感谢 ReNiSh 的解决方法,非常感谢。

You do nothowever need to use the library approach to implement the 'require_once' of hDash. I have now written a walkthrough for getting hDash installed and running, which you can find here: http://harpanet.com/programming/php/codeigniter/dashboard/walkthrough

但是需要使用库的方式来实现HDASH的“require_once”。我现在已经编写了安装和运行 hDash 的演练,您可以在这里找到:http://harpanet.com/programming/php/codeigniter/dashboard/walkthrough

Also, note that as of yesterday, 3rd Feb 2014, hDash has been updated to version 1.2.

另请注意,截至昨天,即 2014 年 2 月 3 日,hDash 已更新至 1.2 版。

回答by user3713530

I am using PDF Parser from http://pdfparser.org/

我正在使用来自http://pdfparser.org/ 的PDF 解析器

I create files application/libraries/pdf.php

我创建文件 application/libraries/pdf.php

class Pdf
{
    public function __construct()
    {
        require_once APPPATH."/third_party/pdfparser.php";
    }
}

Then I create file application\third_party\pdfparser.php

然后我创建文件 application\third_party\pdfparser.php

if (!defined('pdfparser')) {
    define('pdfparser', dirname(__FILE__) . '/');
    require(pdfparser . 'pdfparser/autoload.php');
}

Last, I include PDF Parser Library in Directory => application\third_party\pdfparser

最后,我在 Directory => application\third_party\pdfparser 中包含 PDF Parser Library