⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

callback_before_update $post_array Value Null



Danial Habibi

Danial Habibi
  • profile picture
  • Member

Posted 16 April 2016 - 14:24 PM

I have a Controller like this, using callback_before_update to update a field in another table, but I can't get a value from the variable $post_array, as it instead returns null; any idea why?
$crud = new grocery_CRUD();
    $crud->set_table('product');
    $crud->display_as('category_idcategory', 'Category');
    $crud->display_as('Brand_idBrand','Brand');
    $crud->set_field_upload('product_url_image','assets/uploads/files');
    $crud->set_relation('category_idcategory','category','name');
    $crud->set_relation('Brand_idBrand','brand','brand_name');

    $crud->fields('idProduk','product_name','product_url_image','Price_Class_1','Price_Class_2','Price_Class_3','category_idcategory','Brand_idBrand');
    $crud->callback_edit_field('Price_Class_1',array($this,'callback_price_1'));
    //$crud->callback_field('Price_Class_1',array($this,'callback_price_1')); 
    $crud->callback_field('Price_Class_2',array($this,'callback_price_2')); 
    $crud->callback_field('Price_Class_3',array($this,'callback_price_3')); 
    $today = date("Y-m-d H:i:s");  
    $crud->field_type('lastUpdate', 'hidden',$today);
    $crud->callback_column('Price_Class_1',array($this,'getPrice1'));
    $crud->callback_column('Price_Class_2',array($this,'getPrice2'));
    $crud->callback_column('Price_Class_3',array($this,'getPrice3'));

      $crud->callback_before_update(
    function ($post_array,$primary_key)
    {
         unset($post_array['Price_Class_1'],$post_array['Price_Class_2'],$post_array['Price_Class_3']);

      //Or do something with your post arrat here
      if($primary_key !== null)//This means that you update and not insert something
      {
          $priceUpdate = array("price" => $post_array['Price_Class_1']);//THIS ONE RETURN NULL
       //$this->db->update(....);
       $this->db->update('price',$priceUpdate,array('product_idProduk'=>$primary_key,'priceClass_idpriceClass'=>1));

      }
      else
      {
       //$this->db->insert(....);
      }

      return $post_array;

    }
);

Paul Savostin

Paul Savostin
  • profile picture
  • Member

Posted 03 May 2016 - 16:03 PM

I dont get it - first u unset value and then u try to get it, offcourse it will be NULL