[eluser]reglarecneps[/eluser]
Hello,
I'm really stumped by this error code that keeps coming up.
Code:
Fatal error: Call to a member function add() on a non-object in /.../system/application/models/customer_model.php on line 37
I am calling the 'add' function of my address model, but for some reason the model is not loading correctly. As you can see in the 'get_all_details' function, I also use the address model's 'get' function and it works wonderfully that time.
Please help!!
customer_model.php
Code:
<?php
class Customer_model extends Model {
function Customer_model() {
parent::Model();
}
function get_all_details($id) {
$this->load->model('address_model');
$this->load->model('location_model','location');
$this->load->model('job_model','job');
$table_info = $this->get_customer_table_info_for($id); //TODO:build get_customer_table_info_for($id)
$address = $this->address_model->get($table_info[0]['address_id']); //TODO:build address model, and get($id)
$locations = $this->location->minimal_get_all_for($id);
$jobs = $this->job->minimal_get_all_for($id,'active');
$details = array(
'name' => $table_info[0]['name'],
'id' => $table_info[0]['id'],
'address' => $address[0],
'locations' => $locations,
'jobs' => $jobs
);
return $details;
}
...
function add_new_customer($data) {
$this->load->database();
$this->load->model('address_model');
$address_id = $this->address_model->add(array($data['street1'],$data['street2'],$data['city'],$data['state'],$data['zip']));
$this->db->query("INSERT INTO 'customers' ('name' ,'address_id') VALUES (?,?)",array($data['name'],$address_id));
}
}
?>
address_model.php
Code:
<?php
class Address_model extends Model {
function Address_model() {
parent::Model();
}
function get($id) {
$this->load->database();
$table_data = $this->db->query('SELECT * FROM addresses WHERE id = '.$id)->result_array();
return $table_data;
}
function add($data) {
echo 'got here';
$this->load->database();
if ($this->db->query("INSERT INTO 'addresses' ('street1', 'street2' ,'city' ,'state' ,'zip') VALUES (?,?,?,?,?)",$data)) {
return $this->db->insert_id();
} else {
return false;
}
}
}
?>