⚠ 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

callback_after_update doesn't work



mau
  • profile picture
  • Member

Posted 07 January 2014 - 02:04 AM

Hi

I try to find some help to understand why a callback_after_update doesn't work.

The code I wrote in the controller is:

    public function mostra_sgestore()
    {
        $session_tipo = $this->session->userdata('menuTipo');
        if($this->_session_is_ok($session_tipo))
        {
            $session_nome = $this->session->userdata('nomeutente');
            $this->_connselDB($session_tipo);
            $crud = new grocery_CRUD();

            $crud->set_table('Tab1');
            $crud->where('Tab1.cod_fisc',$session_nome);
            $crud->set_relation('id_gest_saldo','Tab1','nome');
            $crud->display_as('cod_fisc','Codice fiscale');
            $crud->display_as('id_gest_saldo','Gestore saldo');
            $crud->set_subject('Gestore');
            $crud->unset_add();
            $crud->unset_edit_fields('is_admin','id_gest_saldo');
            $crud->required_fields('nome','cod_fisc','password','email');
            $crud->columns('nome','cognome','cod_fisc','telefono','email','id_gest_saldo','max_saldo','importo_unitario','punti_importo');
            $crud->callback_after_update(array($this, '_crypt_passwd'));

            $output = $crud->render();
            $dati = array();
            $dati['sitepath'] = 'Scheda';
            $output->dati=$dati;
            $this->_example_output($output);
        }
    }

and the function called from callback is:

    function _crypt_passwd($post_array,$primary_key)
    {
        $nome_tabella = 'Tab1';
        $nome_tabella1 = 'Tab2';
        $gest_sql = "SELECT password FROM $nome_tabella WHERE id_gest = \"$primary_key\"";
        $cli_sql = "SELECT password FROM $nome_tabella1 WHERE id_cli = \"$primary_key\"";
        $risultato = $this->db->query($gest_sql);

        if ($risultato->num_rows() === 1)
        {
            $riga = $risultato->row();
            $passwd = $riga->password;
            $sql = "UPDATE $nome_tabella SET password=sha1(\"$passwd\") WHERE id_gest=\"$primary_key\"";
            return $this->db->query($sql);
        }
        else
        {
            $risultato = $this->db->query($cli_sql);
            if ($risultato->num_rows() === 1)
            {
                $riga = $risultato->row();
                $passwd = $riga->password;
                $sql = "UPDATE $nome_tabella1 SET password=sha1(\"$passwd\") WHERE id_cli=\"$primary_key\"";
                return $this->db->query($sql);
            }
            else
            {
                return FALSE;
            }
        }
    }
 

It seems that if I edit a row, for example of Tab1, and I update the record after a modification there isn't the call to callback_after_update.I followed the informations of the documentation but something is wrong. If someone can help me it will be appreciated a lot.
Thanks in advance.

 

Mau

 

SOLVED: I used 'state' to intercept the end of edit. Not so fine but it works.