⚠ 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

how to set call back functions in to one field ?



Ishan Rakitha
  • profile picture
  • Member

Posted 26 January 2014 - 21:12 PM

I need to execute my 2 callback functions only if the password field is modified. how can i set it into password field ? currently i cant update any other record in the table because callbacks are running unnecessarly.

 

 

my code sample 

   function login() {
        $crud = new grocery_CRUD();

        $crud->set_table('login');
        $crud->set_subject('Login');

        $crud->set_relation('staff_id', 'staff', '{staff_id} - {staff_name}');
        $crud->display_as('staff_id', 'Staff ID / Staff Name');

        $crud->set_relation('access_level_id', 'access_level', '{access_level_description}';
        $crud->display_as('access_level_id', 'Access Level');

        $crud->change_field_type('password', 'password');

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

        $crud->required_fields('user_name', 'password', 'staff_id', 'access_level_id');
        $output = $crud->render();
        $this->_example_output($output);
    }

Thank You.

 


Amit Shah
  • profile picture
  • Member

Posted 29 January 2014 - 08:10 AM

Hi Ishan,

 

Well u tried to explain the issue but didnt clarify the scenario as such...If u can.,.. we may be in better position to help u

but let me share you as how you may go ahead ....

1 - u have before update...here u can retrieve the primary key .. .and the record along with the same....

2 - u can then compare the passwords ... from the retrieved entry and the post_array

3 - if different - u can make call to whatever calls u want in before update... else.. what u can do is.. set the callable flag in the session

4 - make a post_update callback.. and there check the flag if it was supposed to be called or not.. and take necessary action accordingly..

 

Hope this helps up!


Ishan Rakitha
  • profile picture
  • Member

Posted 05 February 2014 - 17:39 PM

Thank you for the information amit, I ll try your method. :)