I want to set up my first project in CodeIgniter which includes a database. I've made the proper configurations for database like shown in this tutorial: Everything You Need to Get Started With CodeIgniter.
I have created my database in phpMyadmin. When try to access the project in my localhost this is the error: After changing password from 'root' to ' ' now the error is this:
Fatal error: Class 'Model' not found in C:\xampp\htdocs\ci\application\models\diploma_model.php on line 2
This is my model cpde:
<?php
class diploma_model extends Model {
function diploma_model()
{
// Call the Model constructor
parent::Model();
}
function getData()
{
//Query the data table for every record and row
$query = $this->db->get('data');
if ($query->num_rows() > 0)
{
//show_error('Database is empty!');
}else{
return $query->result();
}
}
}
?>
Im new at codeIgniter. Can someone explain why this error occurs? Thanks!
</div>
Your tutorial that you have read is very out of date. The current codeigniter website is here
It would be worth reading through here
This is the correct way for CI model and anatomy-of-a-model I think because you just extend Model and no CI_Model
And your construct is wrong to.
On autoload.php I would autoload database.
$autoload['libraries'] = array('database');
Filename Diploma_model.php
<?php
class Diploma_model extends CI_Model {
public function __construct() {
// Call the Model constructor
parent::__construct();
}
function getData() {
$query = $this->db->get('data');
// This > means greater. So will return results if any found!
if ($query->num_rows() > 0) {
return $query->result();
//return $query->result_array();
} else {
return false;
}
}
}
Loading of the model
<?php
class Example extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('diploma_model');
}
public function index() {
$data['lists'] = $this->diploma_model->getData();
$this->load->view('someview', $data);
}
}
The CI User guide for models
go to application/config/database.php file, and set the user, pass and whatever you want to the database configuration.
You will see something like this:
(...)
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'database_name',
'dbdriver' => 'mysqli',
(...)