⚠ 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

not understand callback_before_update



marco
  • profile picture
  • Member

Posted 27 April 2018 - 08:19 AM

Hi everyone,

 

I'have some trouble with callback_before_update.

 

It seems to the callback is ignored...

$crud->callback_before_update(array($this,'addition_cout_participants'));

function

    function addition_cout_participants($post_array, $primary_key)
    {
        $this->db = $this->load->database('formations', true);
        $this->db->select('personne_id');
        $this->db->where('participation_id', $primary_key);
        $query = $this->db->get('join_pepa');
        $nb_participant = 0;
        if ($query->num_rows() > 0)
        {
            foreach ($query-result() as $row)
            {
                $nb_participant++;
            }
        }

        $montant_total = $post_array['coutFormation'] * $nb_participant;
        
        $post_array['coutTotal'] = $montant_total;

       return $post_array;

}

that not work !

 

If I try a simple thing like

function addition_cout_participants($post_array, $primary_key)
{
    $post_array['coutTotal'] = 12;
    return $post_array;
}

$post_array['coutTotal'] is always: 0.00 ; the default value in db (in my db_table coutTotal is a decimal(10,2) field)

 

I also try

     $this->db->where('participation_id', $primary_key);
     $this->db->update('join_pepa', array('coutTotal'=>$montant_total));

But nothing...

 

 

Someone can help me ?

 

Thanks


marco
  • profile picture
  • Member

Posted 27 April 2018 - 10:34 AM

oki....

foreach ($query-result() as $row)

->

foreach ($query->result() as $row)

and

$crud->callback_before_update(array($this,'addition_cout_participants'));

->

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

with

$this->db->where('participation_id', $primary_key);
$this->db->update('pepa', array('coutTotal'=>$montant_total));
return true;

SOLVED !