Welcome Guest, Not a member yet? Register   Sign In
Can't update a controller variable in model
#1

[eluser]mikertjones[/eluser]
Hi

This is frustrating

Controller Clients declares var:

Code:
var $vendor_id;

Controller adds or updates client records using model m_client.
If a vendor_id exists it updates the vendor record, if not it creates a new one.

So, in the Controller Clients.php

Code:
$this->m_client->save_vendor();

and in the model m_client.php

Code:
function save_vendor()
  {
   $num_items = empty($_POST['num_items'])?0:$this->input->post('num_items');
   $vendor_data = array(
    'client_id'=>$this->client_id,
    'auction_id'=>$this->auction_id,
    'vendor_ref'=>$this->input->post('auction_vendor_ref'),
    'reference_address'=>$this->input->post('reference_address'),
    'num_items'=>$num_items);

   if($this->vendor_id)
   {
     $this->db->where('vendor_id',$this->vendor_id);
     $this->db->update('vendor',$vendor_data);
   }else{
     $this->db->insert('vendor',$vendor_data);
     $this->vendor_id = $this->db->insert_id();
   }
} // END fn save_vendor

Testing in the context of the model, if a new vendor record is added, $this->vendor_id has a value.
Testing back in Client controller $this->vendor_id has no value even after the call to m_client->save_vendor.

I am expecting that if a new vendor record is inserted that the line

Code:
$this->vendor_id = $this->db->insert_id();

would update the $this->vendor_id value accessible back in the Controller - I need it to call another model function.

Any thoughts?

Thanks

Mike


Messages In This Thread
Can't update a controller variable in model - by El Forum - 05-10-2012, 02:14 AM
Can't update a controller variable in model - by El Forum - 05-10-2012, 05:25 AM
Can't update a controller variable in model - by El Forum - 05-10-2012, 08:24 AM
Can't update a controller variable in model - by El Forum - 05-10-2012, 10:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB