1
私はこのようなコントローラを持っていますが、callback_before_updateを使って別のテーブルのフィールドを更新していますが、変数$ post_arrayから値を取得できません。どんな考え?callback_before_update Grocery Update Value Null
$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;
}
);