我正在制作发票表单, 它从2个模型Invoice和InvoiceDetail中检索数据 当我提交表格时,它给了我
错误500:未定义的索引:site_name。
public function actionCreate()
{
$model=new Invoice;
$detail = new InvoiceDetail();
if(isset($_POST['Invoice']))
{
$model->attributes=$_POST['Invoice'];
if(isset($_POST['InvoiceDetail'])){
$detail = $_POST['InvoiceDetail'];
foreach($detail as $key=>$details){
$det = new InvoiceDetail();
$det->attributes = array(
'invoice_id' => $model->id,
'site_name' => $detail['site_name'][$key],
'do_number' => $detail['do_number'][$key],
'description' => $detail['description'][$key],
'quantity' => $detail['quantity'][$key],
'rate' => $detail['rate'][$key],
'amount' => isset($detail['amount'][$key])?$detail['amount'][$key]:NULL,
);
$det->save(false);
}
}
}
$this->layout='columnInvoice';
$this->render('create',array(
'model'=>$model,
'detail' => $detail
));
}
答案 0 :(得分:1)
使用$detail[$key]['site_name']
而非$detail['site_name'][$key]
。
但您也可以使用$details['site_name']