필드를 테이블에 삽입하고 ID를 가져 오려고합니다 (테이블의 PRIMARY KEY가 AUTO INCREMENT라고 가정). 그 레코드의 자동 증분 ID가 두 번째 테이블에 삽입되어야합니다. 나는 분명히 $ this-> db-> insert_id()를 리턴 할 수있다. 그러나 그 이후에는 컨트롤러의 값에 어떻게 접근 하는가?
변수에서 정의하고 컨트롤러에서 액세스하려고했지만 작동하지 않았습니다.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: insert_id
Filename: controllers/POS.php
Line Number: 87
모델 :
function populate_pos_purchase_table($posPurchase) {
$this->db->trans_begin();
$this->db->insert('pos_purchase', $posPurchase);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
return false;
}
else {
$this->db->trans_commit();
$insert_id = $this->db->insert_id();
return $insert_id;
return true;
}
}
컨트롤러 :
function update_payment_details() {
$newPayment = array (
'pos_id' => $insert_id, // Line Number: 87
'payment_description' => 'Point of Sales',
'payment_method' => $this->input->post('payment_method'),
'payment_date' => $this->input->post('payment_date'),
'paid_amount' => $this->input->post('total'),
'due_amount' => 0
);
$this->pos_model->populate_new_payment_table($newPayment);
$this->index();
}
모델에서 함수는 이와 같이 두 번 연속으로 반환 할 수 없습니다. http://php.net/manual/en/function.return.php 문서를 참조하십시오. "함수 내에서 호출 된 경우 return 문은 현재 함수의 실행을 즉시 끝내고 함수 호출의 값으로 인수를 반환하고 return은 eval() 문 또는 스크립트 파일의 실행을 종료합니다." – envysea
@envysea 감사합니다. 나는 그 사실을 몰랐다. –