Reputation: 373
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?
Upvotes: 1
Views: 2114
Reputation: 3253
Since you're calling the overview class as a library, save that class as Overview.php
inside 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() {
//....
}
}
Upvotes: 0
Reputation: 22532
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() {
}
}
Upvotes: 1