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.