[eluser]why.you.and.i[/eluser]
Hello, i'm new at CI and i'm having almost the same problem here. It's my error:
MY ERROR:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Hello::$Hello_model
Filename: admin/hello.php
Line Number: 15
Fatal error: Call to a member function getData() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/c4/application/controllers/admin/hello.php on line 21
MY CODE:
Here is my controller (hello.php)
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Hello extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->model('hello');
$data['result'] = $this->Hello_model->getData();
$this->load->view('hello', $data);
}
}
And my models (hello.php)
Code:
<?php
class Hello_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
function getData()
{
$query = $this->db->get('data');
if($query->num_rows()==0) { /*SHOW SOME ERROR HERE*/ }
else { return $query->result(); }
}
}
?>
WHAT I'VE TRIED
If i change my model and call the function directly by using
Code:
$data['result'] = Hello_model::getData();
it works anyhow. And i have added to load database in my autoload. Here is my autoload:
application/config/autoload.php
Code:
$autoload['libraries'] = array('database');
Is there something i'm missing? Thank you for your time.