Homemodel.php
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class HomeModel extends CI_Model{
private $DB1, $DB2;
function __construct()
{
parent::__construct();
$this->DB1 = $this->load->database('sample');
}
public function getData(){
/* @var $query type */
$query = $this->DB1->get('employee');
return $query->result(); // Standard Query With Multiple Results (Object Version)
}
}//class
Home.php(Controller)
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class Home extends CI_Controller{
// private $View;
public function index(){
$this->load->model('HomeModel');
$db_data['eduData'] = $this->HomeModel->getData();
$this->load->view('View', $db_data);
}
}
I have tried above way to fetch data from db, but i got error as
Fatal error: Call to a member function get() on a non-object in D:\xampp\htdocs\Codeigniter\application\models\HomeModel.php on line 21
how to fix that error? and also i have another doubt for Controller Home.php file , i have defined index() call default, and i have tried to change that function name i got error how to fix that error also?