本文整理汇总了PHP中app\models\Books::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Books::save方法的具体用法?PHP Books::save怎么用?PHP Books::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Books
的用法示例。
在下文中一共展示了Books::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* 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]);
}
示例2: actionCreate
/**
* 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]);
}
}
示例3: actionCreate
/**
* 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())]);
}
}
示例4: actionCreate
/**
* 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]);
}
}
示例5: actionCreate
/**
* 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]);
}
}
示例6: actionCreate
/**
* 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()]);
}
}
示例7: actionCreate
/**
* 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]);
}
}
示例8: actionCreate
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]);
}
}
示例9: actionCreate
/**
* 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]);
}
}
示例10: actionCreate
/**
* 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]);
}
}
示例11: actionCreate
/**
* 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]);
}
}
示例12: actionCreate
/**
* 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]);
}
示例13: actionCreate
/**
* 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()]);
}
}
示例14: update
/**
* 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();
}
示例15: actionCreate
/**
* 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]);
}
}