我正在创建发票表格,给我 500 未定义的索引错误

I am working on create invoice form, gives me 500 undefined index error

我正在制作发票表格, 它从 2 个模型 Invoice 和 InvoiceDetail 中检索数据 当我提交表格时,它给了我

error 500: undefined index: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
    ));
}

使用 $detail[$key]['site_name'] 而不是 $detail['site_name'][$key]

但你也可以使用 $details['site_name']