/** * Creates a new Rents model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Rents(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Rents model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Rents(); $model->user_id = Yii::$app->user->id; $model->rent_date = date('Y-m-d', time()); $model->prev_date = date('Y-m-d', strtotime('+ 2 weeks', time())); $model->status = 'rented'; if (isset($_GET['book_id'])) { $model->book_id = $_GET['book_id']; $model->save(); $book = Books::findOne($model->book_id)->updateStatus($model->status); return $this->redirect(['view', 'id' => $model->id]); } else { print_r(Yii::$app->request->get()); return $this->render('create', ['model' => $model]); } }