Reputation: 1024
Hi all I am having an error and I just can't see why codeigniter is throwing the error:
controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Management extends CI_Controller {
public function index(){
//calls login page view
$this->managementView();
}
public function managementView(){
//loads course page view
$users['users'] = $this->management_model->getInfo();
$this->load->view("header");
$this->load->view("users", $users);
$this->load->view("footer");
}
}
Model:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Management_model extends CI_Model{
function getInfo(){
$query = $this->db->get("users");
$result = $query->result_array();
return $result;
}
}
I am receiving the following error, I just can't seem to see what the hell I'm doing wrong - I'm new to web stuff so don't know what these errors indicate:
Fatal error: Call to a member function getInfo() on a non-object
also see this:
Severity: Notice
Message: Undefined property: Management::$management_model
Filename: controllers/management.php
Line Number: 12
I can't see the issue? - If anyone could point it out would be much appreciated.
Upvotes: 0
Views: 128
Reputation: 618
you need to load the model before calling any function from the model. for eg:
$this->load->model('management_model');
$users['users'] = $this->management_model->getInfo();
or you can load it via the constructor.
function __construct() {
parent::__construct();
$this->load->model('management_model');
}
}
the notice you are getting is clearly telling about the undefined property management model you can see more about this here
Upvotes: 1
Reputation: 3125
use
$this->load->model('management_model');
before
$users['users'] = $this->management_model->getInfo();
Upvotes: 0
Reputation: 864
Initially you can load the model like this
$this->load->model('management_model');
then only u can use the object to call function
you need some more clarity Click
Upvotes: 0
Reputation: 20469
You dont appear to ever set the management_model property in your controller.
I would expect to see something like this somewhere in your controller:
$this->management_model = new Management_model();
Upvotes: 1