简体   繁体   English

在无法在Grocery CRUD中插入之前回叫

[英]Call back before insert not work in Grocery CRUD

My Controller, inserts a row in invHdrData Table, i want the Max Doc Number in that Table to insert a Doc Number automatically The callback before insert not works. 我的控制器在invHdrData表中插入一行,我希望该表中的“最大文档号”自动插入文档号。插入前的回调无效。 So Where is the problem? 那么问题出在哪里呢? I would greatly appreciate it if you kindly give me some answers :) 如果您能给我一些答案,我将不胜感激:)

My 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);
}

Another Function in 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;
}

My Model: 我的模特:

    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;
}

Problem Solved. 问题解决了。 I changed the controller to the following: 我将控制器更改为以下内容:

    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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM