[eluser]Unknown[/eluser]
Hi, I'm having an issue using models in CI 2.0.3
My code is the following:
Controller class:
Code:
<?php
class Toot extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('toot_model', '', TRUE);
}
function index(){
$data['title'] = 'Welcome!!';
$this->load->view('header', $data);
$this->load->view('toot_view', $data);
$this->load->view('footer');
}
function search(){
$data['title'] = 'Search Results';
$search_string = $this->input->post('search_string'); // Use any string here instead.
$data['search_result'] = $this->toot_model->get_search_results($search_string);
$this->load->view('header', $data);
$this->load->view('search_view', $data);
$this->load->view('footer');
}
}
?>
Model Code:
Code:
<?php
class Toot_model extends CI_Model{
function __construct(){
parent::__construct();
}
function get_search_results($search_string){
$this->load->database(); // Database is defined in 'Config/database.php'
$this->db->like('city', $search_string);
$result = $this->db->get('places');
}
}
?>
When I run the project and do search($search_string) i got the following error:
Fatal error: Call to a member function database() on a non-object in C:\xampp\htdocs\toot_project\application\models\toot_model.php on line 9
While if I copied toot_model.php to Controllers folder it works fine as a controller.
What is the problem then ??
NOTE:
I've tried to remove
Code:
$this->load->database();
but I got the following:
Fatal error: Call to a member function like() on a non-object in C:\xampp\htdocs\toot_project\application\models\toot_model.php on line 10
Config files attached.