/** * Creates a new Bills model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Bills(); if (Yii::$app->request->isPost) { echo Json::encode(Yii::$app->request->post()); } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionBill() { $model = new Bills(); if (Yii::$app->request->isPost) { $bills = Yii::$app->request->post('Bills'); for ($i = 0; $i < sizeof($bills); $i++) { $model = new Bills(); $model->billrecord = $bills['billrecord']; $model->pament_mode = $bills['pament_mode']; $model->watches_id = $bills['watches_id'][$i]; $model->quantity = $bills['quantity'][$i]; if ($bills['watches_id'][$i] == '' || $bills['quantity'][$i] == '') { continue; } else { if (!$model->save()) { throw new Exception('Bill not saved' . Json::encode($model->getErrors())); } $bill_id = $model->billrecord; } } return $this->redirect(array('site/report/', 'billId' => $bill_id)); } return $this->render('bill', ['model' => $model, 'count' => 0]); }