gpt4 book ai didi

php - 插入前回调在 Grocery CRUD 中不起作用

转载 作者:行者123 更新时间:2023-11-29 19:25:23 24 4
gpt4 key购买 nike

我的 Controller ,在 invHdrData 表中插入一行,我希望该表中的最大文档编号自动插入文档编号插入之前的回调不起作用。那么问题出在哪里呢?如果您能给我一些答案,我将不胜感激:)

我的 Controller :

        public function sanads()
{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('invhdrdata');
$crud->set_subject('BLAH BLAH BLAH');
$crud->columns('FiscalYear','StoreNo','DocType','CreateDate','UpdateDate');
$crud->fields('FiscalYear','StoreNo','DocType','DocNo','CreateDate','UpdateDate');
$crud->callback_before_insert(array($this,'maxDocNoCon'));
$crud->field_type('DocNo','invisible');
$output = $crud->render();
$this->_example_output($output);
}

Controller 中的另一个函数:

    public function maxDocNoCon($post_array) {
$this->load->model('inv_model');
$post_array['DocNo'] = $this->inv_model->maxDocNoMod($post_array['FiscalYear'],$post_array['StoreNo'],$post_array['DocType']);
$test['DocNo'] = (int)explode(",", $post_array['DocNo'])+1;
return $test;
}

我的模型:

    function maxDocNoMod($FiscalYear,$StoreNo,$DocType){
$this->db->select_max('DocNo');
$this->db->where('FiscalYear', $FiscalYear);
$this->db->where('StoreNo', $StoreNo);
$this->db->where('DocType', $DocType);
$data = $this->db->get('invhdrdata');
if ($data->num_rows() != 1) {
// there should only be one row - anything else is an error
return false;
}
return $data->row()->DocNo;
}

最佳答案

问题已解决。我将 Controller 更改为以下内容:

    public function maxDocNoCon($post_array) {
$this->load->model('inv_model');
$post_array['DocNo'] = $this->inv_model->maxDocNoMod($post_array['FiscalYear'],$post_array['StoreNo'],$post_array['DocType'])+1;
if ($post_array['DocNo'] == 1){
$post_array['DocNo'] = 10001;
}
return $post_array;
}

关于php - 插入前回调在 Grocery CRUD 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42180504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com