/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Books(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } return $this->render('create', ['model' => $model]); }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Books(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->renderAjax('create', ['model' => $model]); } }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Books(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'authors' => $this->getAuthorsArray(Authors::find()->all())]); } }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Books(); $model->date_create = $model->date_update = date('Y-m-d H:i:s'); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(isset($_POST['referer']) ? $_POST['referer'] : '/'); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $book = new Books(); $author = new Authors(); if ($book->load(Yii::$app->request->post()) && $book->save()) { return $this->redirect(['view', 'id' => $book->id]); } else { return $this->render('create', ['model' => $book, 'author' => $author]); } }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($closeOnLoad = false) { $model = new Books(); $data = $this->filterData(Yii::$app->request->post()); if ($model->load($data) && $model->save()) { return $this->redirect(['view', 'id' => $model->id, 'closeOnLoad' => $closeOnLoad]); } else { return $this->render('create', ['model' => $model, 'authors' => $this->getAuthorsForDropDownList()]); } }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Books(); if ($model->load(Yii::$app->request->post())) { $model->uploadImage(); return $model->save() ? $this->redirect(['index']) : var_dump($model); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreate() { $model = new Books(); if ($model->load(Yii::$app->request->post())) { $model->uploadImage(); $model->date_create = date('Y-m-d'); $model->date_update = date('Y-m-d'); $model->save(); return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Books(); $model_b_a_rel = new BookAuthorRel(); $authorsArr = Authors::authorArr(); if ($model->load(Yii::$app->request->post()) && $model_b_a_rel->load(Yii::$app->request->post())) { $model->save(); $model_b_a_rel->b_id = $model->id; $model_b_a_rel->saveMultiple(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'model_b_a_rel' => $model_b_a_rel, 'authorsArr' => $authorsArr]); } }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Books(); if ($model->load(Yii::$app->request->post()) && $model->upload()) { //var_dump(Yii::$app->request->post());die(); if ($model->save()) { return $this->redirect(['index']); } else { return $this->render('create', ['authors' => Authors::find()->all(), 'model' => $model]); } } else { return $this->render('create', ['authors' => Authors::find()->all(), 'model' => $model]); } }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Books(); $modelAuthorsBooks = new AuthorsBooks(); $data = Yii::$app->request->post(); if ($model->load($data) && $model->save()) { $modelAuthorsBooks->a_id = $data['AuthorsBooks']['a_id'][0]; $modelAuthorsBooks->b_id = $model->id; if ($modelAuthorsBooks->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model, 'modelAuthorsBooks' => $modelAuthorsBooks]); } }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Books(); if ($model->load(Yii::$app->request->post())) { $upload_file = $model->uploadFile(); var_dump($model->validate()); if ($model->validate()) { if ($model->save()) { if ($upload_file !== false) { $path = $model->getUploadedFile(); $upload_file->saveAs($path); } return $this->redirect(['index']); } } } return $this->render('create', ['model' => $model]); }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Books(); if ($model->load(Yii::$app->request->post())) { $image = $model->uploadImage(); if ($image !== false) { $path = $model->getImageFile(); $image->saveAs($path); } // if ($path = $model->upload()) { // $model->preview_image = $path; // } $model->save(); return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model, 'authors' => Authors::getAuthorsList()]); } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request) { $id = $request->get('id'); $book = Books::find($id); $result = Validator::make(Input::all(), ['title' => 'required', 'author' => 'required', 'publisher' => 'required', 'isbn' => "required|max:13|min:13|regex:/^[1-9][0-9]{12}\$/"], ['title.required' => 'Book title is required', 'author.required' => 'Book author is required', 'isbn.required' => 'ISBN is required', 'isbn.max' => 'ISBN must be exactly 13 characters', 'isbn.min' => 'ISBN must be exactly 13 characters', 'isbn.regex' => 'ISBN must contain numbers only.', 'publisher.required' => 'Publisher is required']); if ($result->fails()) { $result->errors()->add('submitted', 1); $result->errors()->add('desc', Input::get('description') !== "" ? TRUE : FALSE); return redirect()->route('books.new')->withErrors($result->errors())->withInput(); } $book->title = $request->get("title"); $book->author_id = $request->get("author_id"); $book->isbn = $request->get("isbn"); $book->description = $request->get('description'); $book->date_published = $request->get('date_published'); $affected = $book->save(); if ($affected > 0) { $book = new Books(); $book->title = $request->get("title"); $book->author_id = $request->get('author_id'); $book->publisher_id = $request->get('publisher_id'); $book->isbn = $request->get("isbn"); $book->description = $request->get('description'); $book->date_published = $request->get('date_published'); $book->record_id = $id; $book->save(); } return redirect()->route('books.home')->with('status', "Update successful")->withInput(); }
/** * Creates a new Books model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $authors_model = Authors::find()->all(); $authors = []; foreach ($authors_model as $author) { $authors[$author->author_id] = $author->firstname . " " . $author->lastname; } $model = new Books(); $post = Yii::$app->request->post(); if (isset(Yii::$app->request->post()["Books"])) { $post["Books"]["date_create"] = date("Y-m-d"); $post["Books"]["date_update"] = date("Y-m-d"); } if ($model->load($post) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'authors' => $authors]); } }