public function actionImportFiles() { if (\Yii::$app->request->getMethod() == 'GET') { return json_encode($this->getFiles_FileSystemOnly(), JSON_UNESCAPED_UNICODE); } if (\Yii::$app->request->getMethod() == 'POST') { $error = ''; $post = \Yii::$app->request->post('post'); $arr_added = []; try { foreach ($post as $f) { $book = new Books(['scenario' => 'import']); $book->filename = $book->title = $f; $book->insert(); $arr_added[] = $f; } } catch (\Exception $e) { return json_encode(['data' => $arr_added, 'result' => false, 'error' => $e->getMessage()], JSON_UNESCAPED_UNICODE); } return json_encode(['data' => $arr_added, 'result' => true, 'error' => ''], JSON_UNESCAPED_UNICODE); } }
private function add($attributes) { /* @var $book Books */ $book = new Books(['scenario' => 'add']); $book->attributes = $attributes; $book->favorite = $book->favorite == null ? 0 : $book->favorite; $book->insert(); }