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


  • 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()
$crud = new grocery_CRUD();
$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'));
$output = $crud->render();
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) 
    ->set('expiry', 'DATE_ADD(expiry,INTERVAL 1 year)', FALSE)
    ->where('id', $hostingid)
else if($paid='yes' && $domainid) 
    ->set('expiry', 'DATE_ADD(expiry,INTERVAL 1 year)', FALSE)
    ->where('id', $domainid)
       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.





#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