当前位置: 首页>>代码示例>>PHP>>正文


PHP Author::save方法代码示例

本文整理汇总了PHP中app\models\Author::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Author::save方法的具体用法?PHP Author::save怎么用?PHP Author::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Author的用法示例。


在下文中一共展示了Author::save方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 /**
  * Страница добавления автора.
  *
  * @return string|\yii\web\Response
  */
 public function actionCreate()
 {
     $modelAuthor = new Author();
     if ($modelAuthor->load(Yii::$app->request->post()) && $modelAuthor->save()) {
         return $this->redirect(['back-author/view', 'id' => $modelAuthor->id]);
     }
     return $this->render('/back/author/create', ['modelAuthor' => $modelAuthor]);
 }
开发者ID:Rey8d01,项目名称:book-catalog,代码行数:13,代码来源:BackAuthorController.php

示例2: runAuthorInsertion

 function runAuthorInsertion($i)
 {
     $author = new Author();
     $author->firstName = 'John' . $i;
     $author->lastName = 'Doe' . $i;
     $author->save(false);
     $this->authors[] = $author;
 }
开发者ID:motin,项目名称:forked-php-orm-benchmark,代码行数:8,代码来源:Yii2MTestSuite.php

示例3: run

 /**
  * Seeds the table.
  *
  * @return void
  */
 public function run()
 {
     $author = new Author();
     $author->first_name = 'Dan';
     $author->last_name = 'Gebhardt';
     $author->twitter = 'dgeb';
     $author->save();
 }
开发者ID:guduchango,项目名称:limoncello-collins,代码行数:13,代码来源:AuthorsTableSeeder.php

示例4: actionCreate

 /**
  * Creates a new Author model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Author();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:Oleg25,项目名称:RGK-Group,代码行数:14,代码来源:AuthorController.php

示例5: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $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();
     }
     $author_id = $request->get('author_id');
     if (intval($author_id) == -1) {
         $new_author = new Author();
         $new_author->author_name = $request->get('author');
         $new_author->save();
         $author_id = $new_author->id;
         // Create copy of newly created author
         $new_author = new Author();
         $new_author->author_name = $request->get('author');
         $new_author->record_id = $author_id;
         $new_author->save();
     }
     $publisher_id = $request->get('publisher_id');
     if (intval($publisher_id) == -1) {
         $new_publisher = new Publisher();
         $new_publisher->name = $request->get('publisher');
         $new_publisher->save();
         $publisher_id = $new_publisher->id;
         // Create copy of newly created publisher
         $new_publisher = new Publisher();
         $new_publisher->name = $request->get('publisher');
         $new_publisher->record_id = $publisher_id;
         $new_publisher->save();
     }
     $book = new Books();
     $book->title = $request->get("title");
     $book->author_id = $author_id;
     $book->publisher_id = $publisher_id;
     $book->isbn = $request->get("isbn");
     $book->description = $request->get('description');
     $book->date_published = $request->get('date_published');
     $book->save();
     $book_id = $book->id;
     // Create copy of newly created book
     $book = new Books();
     $book->title = $request->get("title");
     $book->author_id = $author_id;
     $book->publisher_id = $publisher_id;
     $book->isbn = $request->get("isbn");
     $book->description = $request->get('description');
     $book->date_published = $request->get('date_published');
     $book->record_id = $book_id;
     $book->save();
     return redirect()->route('books.home')->with('status', "New book created");
 }
开发者ID:jmnerd07,项目名称:book-management,代码行数:59,代码来源:BooksController.php

示例6: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $attributes = array_get($this->getDocument(), 'data.attributes', []);
     $rules = ['first_name' => 'required|alpha_dash', 'last_name' => 'required|alpha_dash'];
     $validator = Validator::make($attributes, $rules);
     if ($validator->fails()) {
         throw new BadRequestHttpException();
     }
     $author = new Author($attributes);
     $author->save();
     return $this->getCreatedResponse($author);
 }
开发者ID:jonpitch,项目名称:limoncello-collins,代码行数:17,代码来源:AuthorsController.php

示例7: actionLogin

 public function actionLogin()
 {
     $user_name = \Yii::$app->request->post()['user_name'];
     $password = \Yii::$app->request->post()['pwd'];
     $author_info = new Author();
     $author_info->name = $user_name;
     $author_info->pwd = $password;
     if ($author_info->save()) {
         $author_id = Author::findBySql("select id from author ORDER BY id DESC LIMIT 0,1")->asArray()->all();
         $array = ['error_no' => 0, 'error_msg' => '', 'data' => $author_id[0]];
         echo json_encode($array);
     }
 }
开发者ID:hanjt,项目名称:synchronizeInfo-server,代码行数:13,代码来源:AuthorController.php

示例8: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $this->checkParametersEmpty();
     $attributes = $this->getFilteredInput(array_get($this->getDocument(), 'data.attributes', []));
     /** @var \Illuminate\Validation\Validator $validator */
     $rules = ['first_name' => 'required|alpha_dash', 'last_name' => 'required|alpha_dash'];
     $validator = Validator::make($attributes, $rules);
     if ($validator->fails()) {
         throw new ValidationException($validator);
     }
     $author = new Author($attributes);
     $author->save();
     return $this->getCreatedResponse($author);
 }
开发者ID:resourcemode,项目名称:limoncello-collins,代码行数:19,代码来源:AuthorsController.php

示例9: actionCreate

 /**
  * Создание автораа
  * @return string
  */
 public function actionCreate()
 {
     $model = new Author();
     if ($model->load(Yii::$app->request->post())) {
         $model->name = Yii::$app->request->post('Author')['name'];
         $model->status = Yii::$app->request->post('Author')['status'];
         $model->description = Yii::$app->request->post('Author')['description'];
         $model->country_id = Yii::$app->request->post('Author')['country_id'];
         $model->save(false);
         $authors = Author::find();
         $dataProvider = new ActiveDataProvider(['query' => $authors]);
         return $this->redirect(Url::toRoute('author/index'));
     } else {
         return $this->render('_form', ['model' => $model]);
     }
 }
开发者ID:roman1970,项目名称:lis,代码行数:20,代码来源:AuthorController.php

示例10: setAuthor

 public function setAuthor($v)
 {
     if (!empty($v)) {
         $author = Author::findOneByColumn('author_name', $v);
         if (false !== $author) {
             $this->data['author_id'] = $author->id;
         } else {
             $author = new Author();
             $author->author_name = $v;
             $author->save();
             $this->data['author_id'] = $author->id;
         }
     } else {
         throw new \Exception('Забыли указать автора');
     }
 }
开发者ID:RayManOff,项目名称:my-blog,代码行数:16,代码来源:News.php

示例11: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     if ($request->get('type') == 'async') {
         $validator = Validator::make(Input::all(), ['author_name' => 'required|min:5'], ['author_name.required' => 'Author name is required. Author not saved.', 'author_name.min' => 'Author name must be minimum of 5 characters']);
         if ($validator->fails()) {
             $return['error'] = $validator->errors();
             $return['model'] = ['author_name' => FALSE, 'id' => FALSE];
             echo json_encode($return);
             return;
         }
         $return['error'] = $validator->errors();
         $author = new Author();
         $author->author_name = $request->get('author_name');
         $author->save();
         $author_id = $author->id;
         $author = new Author();
         $author->author_name = $request->get('author_name');
         $author->record_id = $author_id;
         $author->save();
         $return['model'] = ['author_name' => $request->get('author_name'), 'id' => $author_id];
         echo json_encode($return);
         return;
     }
 }
开发者ID:jmnerd07,项目名称:book-management,代码行数:30,代码来源:AuthorsController.php

示例12: function

// --- AUTHORS ---
$app->get('/authors', function () use($app) {
    $authors = Author::all();
    return view('authors.index', ['authors' => $authors]);
});
$app->get('/authors/new', function (Request $request) use($app) {
    return view('authors.new', ['request' => $request]);
});
$app->get('/authors/{id}', function ($id, Request $request) use($app) {
    $author = Author::find($id);
    return view('authors.edit', ['request' => $request, 'author' => $author, 'id' => $id]);
});
$app->post('/authors', function (Request $request) use($app) {
    $this->validate($request, Author::VALIDATION_RULES);
    $new_author = new Author($request->all());
    $new_author->save();
    return redirect('authors/' . $new_author->id);
});
$app->post('/authors/{id}/update', function ($id, Request $request) {
    $this->validate($request, Author::VALIDATION_RULES);
    $author = Author::find($id);
    $author->update($request->all());
    return redirect('authors/' . $author->id);
});
// --- BOOKS ---
$app->get('/books', function () use($app) {
    $books = Book::all();
    return view('books.index', ['books' => $books]);
});
$app->get('/books/new', function (Request $request) use($app) {
    $authors = Author::all();
开发者ID:simonbacquie,项目名称:get-started-with-lumen,代码行数:31,代码来源:routes.php


注:本文中的app\models\Author::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。