Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter Third party class not loading

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

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.

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

Installation path is root/application/third_party/hArpanet/hDash/libraries/dash.php

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

like image 396
Code Lover Avatar asked Jan 09 '14 09:01

Code Lover


People also ask

How to use third party in CodeIgniter?

Steps To Integrate third party library class in CodeIgniter:Step 1: First download a third party library class. Here we are using simple_html_dom. php. Step 2: Now copy it on CodeIgniter's third party folder located at application\third_party.

HOW include external library in CodeIgniter?

php the library you need to add this below code in the controller. $this->load->library ( 'getID3/getid3/getid3', '', 'getid3(you can add any name you want' ); Now to Use this: $this->getid3->your_function($data);

How to autoload library in CodeIgniter 4?

To autoload resources, open the application/config/autoload. php file and add the item you want loaded to the autoload array.


2 Answers

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

for Eg:

--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';
    }
}

load the library using:

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

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

Thank you...

like image 142
ReNiSh AR Avatar answered Oct 18 '22 21:10

ReNiSh AR


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

You do not however 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

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

like image 4
Stackman Avatar answered Oct 18 '22 19:10

Stackman