Ejemplo n.º 1
0
 private function renderList()
 {
     $model = new Book();
     $searchParams = Yii::$app->request->get('Book');
     if ($searchParams) {
         $model->setAttributes($searchParams, false);
         $model->dateFrom = $searchParams['dateFrom'];
         $model->dateTo = $searchParams['dateTo'];
     }
     $provider = $model->search();
     return $this->render('index', ['provider' => $provider, 'model' => $model]);
 }
Ejemplo n.º 2
0
 /**
  * Creates a new Book model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Book();
     if (!empty(Yii::$app->request->post())) {
         $model->setAttributes(Yii::$app->request->post());
         $model->authors = Yii::$app->request->post('authors');
         $model->tags = Yii::$app->request->post('tags');
         $model->formats = Yii::$app->request->post('formats');
         if ($model->save()) {
             $bookFiles = \Yii::$app->basePath . '/files/tmp/book-form/1/';
             $imgFile = \Yii::$app->basePath . '/web/image/book/tmp/1/';
             $this->copyFiles($bookFiles, \Yii::$app->basePath . '/files/books/' . $model->id . '/');
             $this->copyFiles($imgFile, \Yii::$app->basePath . '/web/image/book/' . $model->id . '/');
             $this->deleteFiles(\Yii::$app->basePath . '/files/tmp/book-form/1/');
             $this->deleteFiles(\Yii::$app->basePath . '/web/image/book/tmp/1/');
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }