在上图中,我选择要插入的 3 条记录,我想从模型到 Controller 获取这 3 条记录 id,我想在打印页面的 ajax 成功中访问这些记录
Controller :
public function createPaymentAllocation(){
$bilty_ids = $this->input->post('due_ids');
$biltyCount = count($bilty_ids);
$agent = $this->input->post('agent');
$due_to = $this->input->post('due_to');
for($i = 0; $i < $biltyCount; $i++){
$data = array(
'agent_id' =>$agent,
'pay_dueto' =>$due_to,
'mr_no' =>$bilty_ids[$i],
);
$modelResult = $this->PayRecAllModel->inserPaymentAllocation($data);
$this->PayRecAllModel->changeStatus($bilty_ids[$i]);
}
if(!empty($modelResult)){
$data['PaymentRecAllocation'] = array(
'form_status' => 'true',
'form_message' => 'Payment Recovery has been successfully Allocate'
);
}else{
$data['PaymentRecAllocation'] = array(
'form_status' => 'false',
'form_message' => 'Something went wrong.'
);
}
echo json_encode($data);
}
型号:
public function inserPaymentAllocation($data){
print_r($this->input->post());
exit();
if($this->db->insert('payment_rec_allocn', $data)){
return true;
}else {
return false;
}
}
在模型中的 print_r
之后,它返回以下数组。
Array
(
[agent] => 291
[rec_type] => lr_no
[due_ids] => Array
(
[0] => 7
[1] => 8
[2] => 9
)
)
数据插入 Controller 后如何返回这 3 个 id
。
最佳答案
在代码中添加数组
$modelResult[] = $this->PayRecAllModel->inserPaymentAllocation($data);
关于jquery - 我想将 ids 从模型($data)返回到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57272796/