[ 'class' => 'yii\web\ErrorAction', ], ]; } public function actionIndex() { return $this->render("/default/news",[]); } public function actionList() { return $this->render('/default/newsList', []); } public function actionInactive() { return $this->render('/default/newsInactive', []); } public function actionNew() { return $this->render('/default/newsNew', []); } // ** Рубрики ** public function actionTopiclist() { return $this->render('/default/topicList', []); } public function actionTopicall() { return $this->render('/default/topicAll', []); } public function actionTopicdel($id) { $model = $this->findTopicModel($id); if($model) $model->del($id); return $this->render('/default/topicList', []); } public function actionTopicshow($id) { $model = $this->findTopicModel($id); if($model) $model->Show($id); return $this->render('/default/topicList', []); } public function actionTopicactive($id) { $model = $this->findTopicModel($id); if($model) $model->Active($id); return $this->render('/default/topicList', []); } public function actionTopicsort() { if (isset($_POST['item']) && is_array($_POST['item'])) { $i = 0; $a = array(); // beginTransaction(); было бы неплохо обернуть в транзакцию но хз как это сделать foreach ($_POST['item'] as $item) { $model = $this->findTopicModel($item); $model->order = $i; $a[$model->id] = $i; $model->save(true, ['order']); // print_a($model->errors); $i++; } return json_encode(['status'=>'ok','data'=>$a]); } return json_encode(['status'=>'err']); } public function actionTopiccreate() { $model = new NewsTopic(); if (Yii::$app->request->isPost && Yii::$app->request->post()){ if($model->load($_POST) && $model->save()){ if (is_uploaded_file($_FILES['NewsTopic']['tmp_name']['photo'])) { // $id = -1; //test $model->saveImg($model->id, $_FILES['NewsTopic']['tmp_name']['photo'], $_FILES['NewsTopic']['type']['photo']); } }else{ print_a($model->errors); } return $this->redirect('topiclist'); } return $this->render('/default/topicCreate', ['model'=>$model]); } public function actionTopicupdate($id) { $model = $this->findTopicModel($id); if (Yii::$app->request->isPost && Yii::$app->request->post()){ if($model->load($_POST) && $model->save()){ // обновление фото if (is_uploaded_file($_FILES['NewsTopic']['tmp_name']['photo'])) { $model->saveImg($model->id, $_FILES['NewsTopic']['tmp_name']['photo'], $_FILES['NewsTopic']['type']['photo']); } }else{ print_a($model->errors); } return $this->redirect('topiclist'); } return $this->render('/default/topicUpdate', ['model'=>$model]); } // ** Сюжеты ** public function actionStorylist() { return $this->render('/default/storyList', []); } public function actionStorydel($id) { $model = $this->findStoryModel($id); if($model) $model->del($id); return $this->render('/default/storyList', []); } public function actionStoryshow($id) { $model = $this->findStoryModel($id); if($model) $model->Show($id); return $this->render('/default/storyList', []); } public function actionAjaxstory() { if (Yii::$app->request->isGet && $get = Yii::$app->request->get('q')){ $model = new Story(); $items = $model->search($get, 10); $res = array(); if( $items && is_array( $items ) ){ foreach( $items as $item ){ $res[] = array( 'id'=>$item['id']*1, 'label'=>$item['title'] ); } return json_encode( ['status'=>'ok', 'item'=>$res] ); } } return json_encode( ['status'=>'err'] ); } public function actionStoryactive($id) { $model = $this->findStoryModel($id); if($model) $model->Active($id); return $this->render('/default/storyList', []); } public function actionStorycreate() { $model = new Story(); if (Yii::$app->request->isPost && Yii::$app->request->post()){ if($model->load($_POST) && $model->save()){ if (is_uploaded_file($_FILES['Story']['tmp_name']['photo'])) { // $id = -1; //test $model->saveImg($model->id, $_FILES['Story']['tmp_name']['photo'], $_FILES['Story']['type']['photo']); } }else{ print_a($model->errors); } return $this->redirect('storylist'); } return $this->render('/default/storyCreate', ['model'=>$model]); } public function actionStoryupdate($id) { $model = $this->findStoryModel($id); if (Yii::$app->request->isPost && Yii::$app->request->post()){ if($model->load($_POST) && $model->save()){ // обновление фото if (is_uploaded_file($_FILES['Story']['tmp_name']['photo'])) { $model->saveImg($model->id, $_FILES['Story']['tmp_name']['photo'], $_FILES['Story']['type']['photo']); } }else{ print_a($model->errors); } return $this->redirect('storylist'); } return $this->render('/default/storyUpdate', ['model'=>$model]); } // ** отладка ** public function actionTest() { return $this->render('/default/test', []); } /** * Найти сюжет. * * @param $id * @return Story|null * @throws NotFoundHttpException */ protected function findStoryModel($id) { if (($model = Story::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException('Ой! сюжет не найдена.'); return false; } /** * Найти Ркбрику. * * @param $id * @return Story|null * @throws NotFoundHttpException */ protected function findTopicModel($id) { if (($model = NewsTopic::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException('Ой! рубрика не найдена.'); return false; } }