I’m not sure if this is a bug or just something that wasn’t ever meant to work, but I’m getting a “Fatal Error: Call to a member function get() on a non-object” error when I try to do a simple database call using nested controllers.
My basic setup is that I have a generic controller that loads another controller and then loads a view that just echos the ‘answer_list’ variable.
<?
class Generic extends Controller
{
function Generic()
{
parent::Controller();
}
function index()
{
//Include answer controller
require_once('answer.php');
//Initialize controller
$answer = new Answer();
//Call display() function in answer controller
$data['answers_list'] = $answer->display();
//Load generic view
$this->load->view('generic_view', $data);
}
}
?>
And in the answer controller, I have a pretty simple display() function
class Answer extends Controller
{
function Answer()
{
parent::Controller();
$this->load->model('question_model');
}
function display()
{
$data['query'] = $this->question_model->getAllAnswers();
return $this->load->view('Answer/question_index', $data, true);
}
}
?>
The getAllAnswers() function is in my question_model and just does a simple db->get call.
class Question_model extends Model
{
function Question_model()
{
parent::Model();
}
function getAllAnswers()
{
return $this->db->get('answers');
}
}
I’ve autoloaded the database library, so I know thats not the issue. The php error page is complaining about the “return $this->db->get(‘answers’);” call. Is this supposed to be able to work?
