CodeIgniter第三方类未加载 [英] CodeIgniter Third party class not loading

查看:171
本文介绍了CodeIgniter第三方类未加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现仪表板小部件类(可在此处找到: http://harpanet.com/programming / php / codeigniter / dashboard / index#installation ),但它给我错误无法加载请求的类

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

我试图将此类自动加载并以菜单方式添加到控制器 $ this-> load-> library('dash'),但是

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.

我检查了 dash.php 并发现下面的方法私有函数__example __(),但无法理解开发人员在评论中说的话。

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

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

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

推荐答案

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

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

例如:

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

--in library create a file named 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类了。也可以自动加载库。

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

谢谢...

这篇关于CodeIgniter第三方类未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆