在Grocery CRUD中插入不起作用之前回电

时间:2017-02-11 19:50:56

标签: php mysql codeigniter grocery-crud

My Controller,在invHdrData表中插入一行, 我希望该表中的Max Doc Number自动插入Doc Number 插入前的回调不起作用。 那问题出在哪里? 如果你能给我一些答案,我将不胜感激:)

我的控制器:

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

控制器中的另一个功能:

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

1 个答案:

答案 0 :(得分:0)

解决了问题。 我将控制器更改为以下内容:

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