[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], ], ], ] ); } /** * Lists all TopSlider models. * * @return string */ public function actionIndex() { $squery = \app\models\News::find()->select("news.id,title,post_id,published_from,published_to,".TopSlider::tableName().".id as ts_id")->rightjoin(TopSlider::tableName(), 'news.id = '.TopSlider::tableName().'.post_id'); // print_a($query->createCommand()->queryAll());exit; $query = $squery->createCommand()->queryAll(); //$query = "SELECT * FROM `news`, `top_slider` WHERE `news`.`id` = `top_slider`.`post_id`"; $dataProvider = new ActiveDataProvider([ 'query' => $squery, /* 'pagination' => [ 'pageSize' => 50 ], 'sort' => [ 'defaultOrder' => [ 'id' => SORT_DESC, ] ], */ ]); $provider = new \yii\data\ArrayDataProvider([ 'allModels' => $query, 'pagination' => [ 'pageSize' => 50, ], ]); return $this->render('index', [ 'dataProvider' => $provider, ]); } /** * Displays a single TopSlider model. * @param int $id ID * @return string * @throws NotFoundHttpException if the model cannot be found */ public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), ]); } /** * Creates a new TopSlider model. * If creation is successful, the browser will be redirected to the 'view' page. * @return string|\yii\web\Response */ public function actionCreate() { $model = new TopSlider(); if ($this->request->isPost) { if ($model->load($this->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { $model->loadDefaultValues(); } return $this->render('create', [ 'model' => $model, ]); } /** * Updates an existing TopSlider model. * If update is successful, the browser will be redirected to the 'view' page. * @param int $id ID * @return string|\yii\web\Response * @throws NotFoundHttpException if the model cannot be found */ public function actionUpdate($id) { $model = $this->findModel($id); if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } return $this->render('update', [ 'model' => $model, ]); } public function actionAjaxsave() { $model = new TopSlider(); \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; if ($this->request->isGet) { $g = $this->request->get('TopSlider'); if( !isset($g['published_from']) || !isset($g['published_to']) || $g['published_from'] == '' || $g['published_to'] == '' ){ return ['success' => 'err', 'err'=>'Не установлена дата']; } if ($model->load($this->request->get()) && $model->save()) { return ['success' => 'ok']; } } return ['success' => 'err', 'err'=>'Ошибка сохранения']; } /** * Deletes an existing TopSlider model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param int $id ID * @return \yii\web\Response * @throws NotFoundHttpException if the model cannot be found */ public function actionDelete($id) { $this->findModel($id)->delete(); return $this->redirect(['index']); } /** * Finds the TopSlider model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param int $id ID * @return TopSlider the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TopSlider::findOne(['id' => $id])) !== null) { return $model; } throw new NotFoundHttpException('The requested page does not exist.'); } public function actionFindNews($q = "") { $data = [ "items"=>[], "total_count" => 0 ]; $news = \app\models\News::find()->from(['n use index (calendar)'=>News::tableName(),]) ->andWhere(['OR',[ 'id'=>$q ], ['like','LOWER(title)',mb_strtolower($q)] ]) ->orderBy(['dt_pub'=>SORT_DESC]) ->limit(20)->all(); foreach ($news as $post) { $data['items'][] = [ "id"=>$post->id, "title"=>$post->title, "picture"=>$post->image->getUrl(Image::SIZE_320x180,"webp") ]; $data['total_count']++; } return $this->asJson($data); } }