callback_update

void callback_update(mixed $callback )
Quick Description: This callback escapes the auto update of the CRUD , and runs only the callback.

This callback escapes the auto update of the CRUD , and runs only the callback.

Example:

public function users(){
$crud = new grocery_CRUD();
$crud->set_table('db_user');
$crud->set_subject('User');
$crud->required_fields('user_name');
 
$crud->columns('user_name','email','real_name','active', 'groups');
$crud->fields('user_name','email','password','real_name','active', 'groups');
 
$crud->callback_edit_field('password',array($this,'set_password_input_to_empty'));
$crud->callback_add_field('password',array($this,'set_password_input_to_empty'));
 
$crud->callback_update(array($this,'encrypt_password_and_update'));
 
$output = $crud->render();
$this->_example_output($output);
}
 
function encrypt_password_and_update($post_array, $primary_key) {
$this->load->library('encrypt');
 
//Encrypt password only if is not empty. Else don't change the password to an empty field
if(!empty($post_array['password']))
{
$key = 'super-secret-key';
$post_array['password'] = $this->encrypt->encode($post_array['password'], $key);
}
else
{
unset($post_array['password']);
}
 
return $this->db->update('db_user',$post_array,array('id' => $primary_key));
}
 
function set_password_input_to_empty() {
return "<input type='password' name='password' value='' />";
}