Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更新前回调\u更新值Null_Php_Codeigniter 3_Grocery Crud - Fatal编程技术网

Php 更新前回调\u更新值Null

Php 更新前回调\u更新值Null,php,codeigniter-3,grocery-crud,Php,Codeigniter 3,Grocery Crud,我有一个这样的控制器,使用callback\u-before\u-update更新另一个表中的字段,但我无法从变量$post\u数组中获取值,因为它返回null;知道为什么吗 $crud = new grocery_CRUD(); $crud->set_table('product'); $crud->display_as('category_idcategory', 'Category'); $crud->display_as('Brand_idBra

我有一个这样的控制器,使用callback\u-before\u-update更新另一个表中的字段,但我无法从变量$post\u数组中获取值,因为它返回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;

    }
);

不能在代码中的任何位置定义函数。将此行和定义函数置于代码之外

$crud->callback_before_update(array($this,'function_name'));