1

I am about trying to learn about Codeigniter, here in this try and error project, i want to call function from another class.

Here is the detailed code: controller/admin/dashboard

class Admin extends CI_Controller{
    public function dashboard() {
        $this->load->library("overview");
        $this->overview->method_overview();
    }
}

Where, the overview is a the filename of Overview class that i want to call and the method_overview is a function inside overview class.

Here the overview.php

class Overview extends CI_Controller
{
    public function method_overview() {

    }
}

And this is the error that i got:

Unable to load the requested class: overview

Can somebody please give me solution or explanation?

2 Answers 2

1

Overview class inherit the property of CI_Controller you just inherit Overview class

So it would be

 class Admin extends Overview{
    public function dashboard() {
        $this->load->library("overview");
        $this->method_overview();
    }
}

class Overview extends CI_Controller
{
    public function method_overview() {

    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Since you're calling the overview class as a library, save that class as Overview.phpinside application/libraries. In that file, something similar to:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Overview {

    function __construct() {
        $this->CI =& get_instance(); //gives access to the CI object
    }

    public function method_overview() {
         //....
    }
}

2 Comments

according to this codeigniter.com/userguide2/general/creating_libraries.html, i dont have to put my class on application/libraries directory. Do you think i have to do this? @Mudshark
Straight from the manual: "Your library classes should be placed within your application/libraries folder, as this is where CodeIgniter will look for them when they are initialized."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.