Jump to content


callback_after_update - do the function only if a particular field is updated

callback_after_update particular field only if upadted run

  • Please log in to reply
1 reply to this topic

#1 Mathew Cherian

Mathew Cherian

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 09 July 2015 - 09:56 AM

Hi there,

Just got a confusion here with callback_after_update. 

 

Please find the functions below.

 

 
public function invoices()
{
clearSearchCookies('invoices');
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('invoice');
$crud->set_subject('Invoices');
$crud->edit_fields('hostingid','domainid','paid');
$crud->set_relation('customer','customers','company');
$crud->field_type('paid','true_false', array('No', 'Yes')); 
if($crud->getState() == 'edit') {
$crud->change_field_type('domainid', 'hidden');
$crud->change_field_type('hostingid', 'hidden');
$crud->callback_after_update(array($this, 'extendExpiry'));
$crud->unset_add();
$crud->unset_delete();
$crud->unset_export();
$crud->unset_print();
$output = $crud->render();
$this->_example_output($output); 
$this->output->set_template('admin_default');
}
 
 
function extendExpiry($post_array,$primary_key)
   {
$paid = $this->input->post('paid');   
$hostingid=   $this->input->post('hostingid'); 
$domainid=   $this->input->post('domainid');  
       if($paid='yes' && $hostingid) 
       { 
    $this->db
    ->set('expiry', 'DATE_ADD(expiry,INTERVAL 1 year)', FALSE)
    ->where('id', $hostingid)
    ->update('hosting');
       }
 
else if($paid='yes' && $domainid) 
    { 
  $this->db
    ->set('expiry', 'DATE_ADD(expiry,INTERVAL 1 year)', FALSE)
    ->where('id', $domainid)
    ->update('domain');
  }
       return true;
   } 
 

 

The problem is that whenever i update the  record, the function extendExpiry runs. I just want this function to run only if my 'paid' field is updated. It's now 'update changes' runs even if there is no update. I dont want that. 

 

Here in the above function I have only one field. But I would like to extend it when there are many fields.

 

If there is any workaround also I would be more than happy to implement. Just a newbie in GC.

 

Thanks,

Mathew. 

 



#2 Paul Savostin

Paul Savostin

    Advanced Member

  • Members
  • PipPipPip
  • 229 posts
  • LocationUkraine

Posted 09 July 2015 - 08:01 PM

Hi! I am not clearly understand what you need but that is function run everytime when you save record - this is normal!

You need just find out do something you need has been change. For example, you can get old record by simple database query and compare old value and new one in post array.







Also tagged with one or more of these keywords: callback_after_update, particular, field, only if upadted, run

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users