⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

[solved] callback_after_update/insert



Raboo
  • profile picture
  • Member

Posted 06 June 2012 - 10:53 AM

In my effort to try to circumvent the issue where you cannot join same table several times so you can display each column from the joined table as it's own column I wanted to try to have multiple foreign keys for the same table.

So what i have is table node with column operatingsystem_id and want that to be replicated to to columns os2_id and os3_id.

This is what I've done so far. but still os2_id and os3_id are empty. What am i doing wrong?


$crud->callback_after_insert(array($this, '_callback_updateos'));
$crud->callback_after_update(array($this, '_callback_updateos'));



function _callback_updateos($postarray, $id)
{
$data = array(
'os2_id' => $postarray->operatingsystem_id,
'os3_id' => $postarray->operatingsystem_id
);
$this->db->update('node', $data, array('node_id' => $id));
return true;
}

Raboo
  • profile picture
  • Member

Posted 06 June 2012 - 22:21 PM

I've added this code instead of callback_after_update.

call_user_func(array($this, '_callback_updateos'));


And it displays me this error:

A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Main::_callback_updateos()
Filename: controllers/main.php
Line Number: 93
A PHP Error was encountered
Severity: Warning
Message: Missing argument 2 for Main::_callback_updateos()
Filename: controllers/main.php
Line Number: 93


So it appears that no arguments are sent to the function?

Raboo
  • profile picture
  • Member

Posted 07 June 2012 - 09:42 AM

I really don't understand, why is $postarray and $id null?
I followed the API examples on the site, what am I missing?

Raboo
  • profile picture
  • Member

Posted 07 June 2012 - 14:54 PM

I managed to solve this.

to get a value from $postarray it's
$postarray["operatingsystem_id"]
instead of
$postarray->operatingsystem_id