Jump to content


how to set call back functions in to one field ?

callback one field

  • Please log in to reply
2 replies to this topic

#1 Ishan Rakitha

Ishan Rakitha

    Newbie

  • Members
  • Pip
  • 2 posts
  • LocationSri Lanka

Posted 26 January 2014 - 09: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.

 



#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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!



#3 Ishan Rakitha

Ishan Rakitha

    Newbie

  • Members
  • Pip
  • 2 posts
  • LocationSri Lanka

Posted 05 February 2014 - 05:39 PM

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







Also tagged with one or more of these keywords: callback, one field

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users