codeigniter 将变量传递给同一控制器中的另一个函数得到警告非法字符串甚至变量正确传递

codeigniter Passing variable to another function in same controller got warning illegal string even variable passed correctly

我试图将变量 $passdataqty 与内部数组从 public function inputstokkeluarSedia() 传递到 public function public function check_inputqty($passdataqty) 所有这些功能都位于 1 个控制器

使用此代码:

public function inputstokkeluarSedia()
{
 ...
 $passdataqty = array(
   'id_sedia' => $this->input->post('id_sedia'),
   'stock_keluar' => $this->input->post('qtyinput'),
   'jenis_dok' => $this->input->post('jenisdok'),            
  );
$this->check_inputqty($passdataqty);
...
}

public function check_inputqty($passdataqty)
{
 ...
 $id_sedia = $passdataqty['id_sedia'];
 $jenis_dok = $passdataqty['jenis_dok'];
 $stock_keluar = $passdataqty['stock_keluar'];
 $this->db->select('stock_rincian');

 $this->db->from('persediaan_stock_rincian');
 $this->db->where('id_sedia', $id_sedia);
 $this->db->where('jenis_dok', $jenis_dok);
 $query = $this->db->get()->row()->stock_rincian;
    
 if ($stock_keluar > $query) {
      $this->form_validation->set_message('check_inputqty', 'Kuantitas barang yang ingin 
      dikeluarkan melebihi jumlah stok yg ada!');
      return FALSE;
 } else {
      return TRUE;
 }
}

代码运行良好,但我收到此警告。

Message: Illegal string offset 'id_sedia'

Message: Illegal string offset 'jenis_dok'

Message: Illegal string offset 'stock_keluar'

Message: Trying to get property 'stock_rincian' of non-object

问题是:即使代码有效,如何解决此警告?有人可以解释为什么会出现此警告吗?

问题出在$this->db->get()->row()->stock_rincian
而是使用:

if($this->db->get()->num_rows()>0){
    return True;
}else{
    return False;
}