Welcome Guest, Not a member yet? Register   Sign In
Help: Undefined property: Mysite::$db_model
#1

[eluser]cavancola[/eluser]
Hi guys im getting the following error!!

==========================================

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Mysite::$db_model

Filename: controllers/mysite.php

Line Number: 38

Fatal error: Call to a member function update_record_now() on a non-object in C:\xampp\htdocs\xampp\codeigniter\application\controllers\mysite.php on line 38

===========================================

The problem seems to be with the update controller code

$this->db_model->update_record_now($data, $recID);

any help wud be appreciated.

kind regards

my controller code is

====================

<?php

class Mysite extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
//$data["myValue"] = "this is the new value";
$this->load->model("db_model");
// get our data
$data["records"] = $this->db_model->get_records();
$data["pagetitle"] = 'My Codeigniter Blog';
// view the homepage now
$this->load->view("db_view", $data);
}
function update()
{
//$data["myValue"] = "this is the new value";
$this->load->model("db_model");
// get our data
$data["records"] = $this->db_model->update_record();
// view the homepage now
$this->load->view("update", $data);
}
function update_now()
{
// get the record id
$recID = $_POST['recordid'];
$data = array(
'lastname' => $this->input->post('lastname'),
'firstname' => $this->input->post('firstname')
);
//$this->db->where('id', 40);
//$this->db->update('people', $data);
$this->db_model->update_record_now($data, $recID);
$this->index();
}
function delete()
{
$this->db_model->get_delete();
}
}

?>

===================================

and the model code is

==================================

<?php

class Db_model extends CI_model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}

function get_records()
{
$query = $this->db->query("SELECT * FROM employees");
if($query->num_rows > 0)
{
foreach ($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
}
function update_record()
{
$query = $this->db->query("SELECT * FROM employees WHERE ID=".$this->uri->segment(3) );
if($query->num_rows > 0)
{
foreach ($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
}
// get our values form the update now function
function update_record_now($data, $recID)
{
// create our variable for the record id
$myrecID = $recID;
$this->db->where('ID', $myrecID);
$this->db->update('employees', $data);
}
// delete person by id
}

?>

===========================================
#2

[eluser]bubbafoley[/eluser]
your update_now() and delete() functions in the controller aren't loading the db_model.

the easiest thing to do is put this in the constructor:
Code:
$this->load->model('db_model');
#3

[eluser]cavancola[/eluser]
hey thanks for the reply!!

actually i got the issue sorted!! i forgot to autoload my model in autoload.php

thanks for the reply anyway Smile

S




Theme © iAndrew 2016 - Forum software by © MyBB