Welcome Guest, Not a member yet? Register   Sign In
Model problem
#1

[eluser]Unknown[/eluser]
Hello guys, I did my model following some steps on the guide, but I got the error:

Code:
Fatal error: Call to a member function insert() on a non-object in C:\xampp\htdocs\info\codeigniter\application\models\dia_model.php on line 24

dia_model.php:
Code:
<?php
class Dia_model extends CI_Model {

//var $db;

    function __construct()
    {
        parent::__construct();
  //$this->load->database('test', TRUE);
  //$this->db = $this->load->database('test', TRUE);
  $this->load->database();
    }
    
    function insert_entry($entry)
    {
        $this->db->insert('dias', $entry);
    }
}
?>

stats.php:
Code:
<?php

class Stats extends CI_Controller {

public function __construct()
       {
            parent::__construct();
  
   //$CI =&get;_instance();
   //$CI->load->model('dia_model', 'db');
   $this->load->model('Dia_model');
  
       }

function index()
{
  $teste = array
  (
   'name' => 'John Doon',
   'score' => 150,
   'area' => 'A',
  );
  
  $this->Dia_model->insert_entry($teste);
}
}
?>
#2

[eluser]Otemu[/eluser]
Hi,

I tested your code on 2.1.3 and it worked for me, which version of codeigniter are you using?? If you are using the same version then I can only assume the probably lies within your database settings application\config\database.php or maybe the actual database itself.




Theme © iAndrew 2016 - Forum software by © MyBB