我有这样的模型
function getlastval($prefix,$namatable, $namafield)
{
$this->db->order_by($namafield,'DESC');
$key = $this->db->get($namatable);
if($key->num_rows()>0)
{
$lastval= $key->row()->Kode_Material_Jasa;
$lastval = explode($prefix,$lastval);
$lv = $lastval[1]; //line 18 refer to this line
//return ltrim($lv, '0');
}
else
{
return 0;
}
}
function gencode($prefix, $digit, $lastval)
{
return $prefix . str_pad($lastval+1, $digit, '0', STR_PAD_LEFT);
}
它适用于早期的控制器
function addkategorimaterial()
{
$this->load->model('m_admin');
$lastval = $this->m_admin->getlastval('KKMJ','ms_kategori_material','Kode_Kategori_Material_Jasa');
$data['nextval'] = $this->m_admin->gencode('KKMJ',3,$lastval);
$data['title'] = 'QB Tambah Kategori Material';
$this->load->view('head',$data);
$this->load->view('content/add_kategori_material');
}
它返回KKMJ001
,但在另一个控制器上不起作用
$this->load->model('m_admin');
$lastval = $this->m_admin->getlastval('KMJ','ms_material_jasa','Kode_Material_Jasa');
$data['nextval'] = $this->m_admin->gencode('KMJ',3,$lastval);
$data['kkmj']='';
$data['title'] = 'QB Tambah Material / Jasa';
print_r($data['nextval']);
print_r($lastval);
所以函数会返回KMJ001
并且错误是这样的
我该如何解决这个问题?