Php 用联合编码点火器建立动力学模型
我昨天问了这个问题,但它被删除了,因为管理员说它和其他帖子有类似的问题,但当我在那里检查时,它没有与我相同的问题,所以我会再次问,希望管理员能理解 我在CodeIgniter中有这个模型:Php 用联合编码点火器建立动力学模型,php,codeigniter,query-builder,Php,Codeigniter,Query Builder,我昨天问了这个问题,但它被删除了,因为管理员说它和其他帖子有类似的问题,但当我在那里检查时,它没有与我相同的问题,所以我会再次问,希望管理员能理解 我在CodeIgniter中有这个模型: public function findJoinGroup($select,$where,$table,$join,$groupby) { $this->db->select($select); $this->db->from($table); $this-&g
public function findJoinGroup($select,$where,$table,$join,$groupby)
{
$this->db->select($select);
$this->db->from($table);
$this->db->join($join);
$this->db->where($where);
$this->db->group_by($groupby);
return $this->db->get()->result_array();
}
它有一个参数,我可以动态使用(我的意思是我可以根据控制器使用不同值的模型)-对吗?因此,当我使用控制器时,它将如下所示:
$select = array(
'ta.TR_APP_ID',
'ta.TR_SUB_DATE',
'ta.RB_ID',
'tr.RB_TOTAL',
'count(tdr.DET_RB_ID) as JUMLAH_ITEM',
'ME.EMP_FULL_NAME'
);
$join = array(
'tr_reimburse tr', 'tr.RB_ID = ta.RB_ID',
'tr_detail_reimburse tdr', 'tdr.RB_ID = tr.RB_ID ',
'm_employee me', 'tr.EMP_ID = me.EMP_ID',
);
$where = array(
'EMP_ID' => $empID,
'TR_APP_STATUS ' => '0',
);
$groupby = 'ta.TR_APP_ID';
$data['app'] = $this->Model_online->findJoinGroup($select,$where,'tr_approval ta',$join,$groupby);
我可以设置select的值,我可以设置where的值,等等
但是有一个问题:当我设置join的值时,它不像where和select那样工作
我得到这个错误:
遇到未捕获的异常类型:ArgumentCountError 消息:函数CI\u DB\u query\u builder::join()的参数太少,在第71行的C:\laragon\www\onlineform\application\models\Model\u online.php中传递了1个参数,至少需要2个参数 文件名:C:\laragon\www\onlineform\system\database\DB\u query\u builder.php 电话号码:526 我的问题是如何在中设置这个数组值,以便在变量join内的模型中使用它 因此,我的模型可以用于许多需要连接的情况(单个或多个连接) 我不想这样制作模型,因为这意味着它只能由4个连接使用,当我需要3/2/1连接时,我会再次制作模型
$this->db->select('*');
$this->db->from('table1');
$this->db->join('table2','table1.id=table2.id');
$this->db->join('table3','table2.id=table3.id');
$this->db->join('table4','table3.id=table4.id');
$this->db->join('table5','table5.id=table4.id');
抱歉,我解释了很多,因为我找不到解决方案,我不想管理员删除我的未回复帖子:(
请不要删除此管理员“让人们帮助我:”)使用多维数组。我想这对你很有用
$join = array(
array('tr_reimburse tr', 'tr.RB_ID = ta.RB_ID'),
array('tr_detail_reimburse tdr', 'tdr.RB_ID = tr.RB_ID'),
array('m_employee me', 'tr.EMP_ID = me.EMP_ID'),
);
在模型中使用这个,就像这样
if(!empty($join)):
foreach($join as $j):
$this->db->join($j);
endforeach;
endif;
if(!empty($join)):
foreach($join as $j):
$this->db->join($j);
endforeach;
endif;