Esempio n. 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;
 }
Esempio n. 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]);
 }
Esempio n. 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSec0()
 {
     return $this->hasOne(SecNews::className(), ['id' => 'sec']);
 }
Esempio n. 4
0
 /**
  * Finds the SecNews model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return SecNews the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = SecNews::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 5
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]);
     }
 }