Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = SecNews::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'sid', $this->sid])->andFilterWhere(['like', 'header', $this->header]);
     return $dataProvider;
 }
Beispiel #2
0
 public function actionView($sid, $section)
 {
     $news = News::find()->select('*')->where(['sid' => $sid])->one();
     $sectionM = SecNews::find()->select(['id', 'sid', 'header'])->where(['sid' => $section])->asArray()->one();
     $page = Page::find()->where(['sid' => Yii::$app->controller->id])->select(['id', 'pid', 'sid', 'header'])->one();
     $pages = Page::find()->select(['id', 'pid', 'sid', 'header'])->asArray()->indexBy('id')->all();
     $mode = $pages[$page->id];
     $branch[] = $mode;
     while (!is_null($mode['pid'])) {
         $mode = $pages[$mode['pid']];
         $branch[] = $mode;
     }
     krsort($branch);
     $branch[] = $sectionM;
     $branch[] = ['header' => $news->header];
     return $this->render('view', ['news' => $news, 'branch' => $branch]);
 }
Beispiel #3
0
 /**
  * Updates an existing News model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $sections = SecNews::find()->select(['id', 'header'])->all();
     $sections = ArrayHelper::map($sections, 'id', 'header');
     $params = ['prompt' => 'Выберите секцию…'];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'sections' => $sections, 'params' => $params]);
     }
 }