/**
  * Страница добавления автора.
  *
  * @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]);
 }
 function runAuthorInsertion($i)
 {
     $author = new Author();
     $author->firstName = 'John' . $i;
     $author->lastName = 'Doe' . $i;
     $author->save(false);
     $this->authors[] = $author;
 }
 /**
  * Seeds the table.
  *
  * @return void
  */
 public function run()
 {
     $author = new Author();
     $author->first_name = 'Dan';
     $author->last_name = 'Gebhardt';
     $author->twitter = 'dgeb';
     $author->save();
 }
Example #4
0
 /**
  * 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]);
     }
 }
 /**
  * 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");
 }
 /**
  * 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);
 }
 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);
     }
 }
 /**
  * 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);
 }
Example #9
0
 /**
  * Создание автораа
  * @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]);
     }
 }
Example #10
0
 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('Забыли указать автора');
     }
 }
 /**
  * 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;
     }
 }
// --- 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();