0

I am working on create invoice form, it retrieves the data from 2 models Invoice and InvoiceDetail when I submit the form, it gives me the

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
    ));
}
davejal
  • 6,009
  • 10
  • 39
  • 82
Asif Khan
  • 131
  • 1
  • 13
  • 1
    Possible duplicate of [PHP error: Notice: Undefined index:](http://stackoverflow.com/questions/4465728/php-error-notice-undefined-index) – Liam Dec 07 '15 at 11:34

1 Answers1

1

Use $detail[$key]['site_name'] not $detail['site_name'][$key].

But you could also use $details['site_name']

KiwiJuicer
  • 1,952
  • 14
  • 28