CodeIgniter第三方类没有加载

时间:2014-01-09 09:46:54

标签: php codeigniter

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

我尝试将此类自动加载以及手动添加到我的控制器$this->load->library('dash'),但这也会产生同样的错误。

我已检查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

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

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

3 个答案:

答案 0 :(得分:25)

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

表示例如:

- 在库中创建名为 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';
    }
}

使用以下方式加载库:

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

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

谢谢...

答案 1 :(得分:4)

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

你做但是需要使用库方法来实现hDash的'require_once'。我现在已经编写了一个用于安装和运行hDash的演练,您可以在此处找到:http://harpanet.com/programming/php/codeigniter/dashboard/walkthrough

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

答案 2 :(得分:2)

我正在使用http://pdfparser.org/

中的PDF解析器

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

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

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

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

最后,我在Directory =&gt;中包含了PDF Parser Library。应用\ THIRD_PARTY \ pdfparser