예제 #1
0
 protected function findModel($alias)
 {
     if (($model = News::find()->where(['and', ['alias' => $alias], 'publish_at < ' . Yii::$app->formatter->asTimestamp('now')])->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #2
0
 /**
  * Finds the News model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return News the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = News::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #3
0
 public function actionNews($id)
 {
     $news = News::find()->where('id = :id', [':id' => $id])->with('comments')->one();
     if (!$news) {
         throw new NotFoundHttpException('нет такой новости');
     }
     return $this->render('news', ['news' => $news, 'comment' => new Comment()]);
 }
예제 #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $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, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'publish_at' => $this->publish_at, 'meta_title' => $this->meta_title, 'meta_description' => $this->meta_description]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'summary', $this->summary])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'alias', $this->alias]);
     return $dataProvider;
 }
예제 #5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find()->orderBy('date DESC');
     $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, 'date' => $this->date, 'category_id' => $this->category_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
예제 #6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $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(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias]);
     $query->andFilterWhere(['>=', 'created_at', $this->created_at ? strtotime($this->created_at . ' 00:00:00') : null])->andFilterWhere(['<=', 'created_at', $this->created_at ? strtotime($this->created_at . ' 23:59:59') : null])->andFilterWhere(['>=', 'publish_at', $this->publish_at ? strtotime($this->publish_at . ' 00:00:00') : null])->andFilterWhere(['<=', 'publish_at', $this->publish_at ? strtotime($this->publish_at . ' 23:59:59') : null]);
     return $dataProvider;
 }
예제 #7
0
 public function search($params)
 {
     $query = News::find();
     if (!isset($params['sort'])) {
         $query->orderBy(['created_at' => SORT_DESC]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->current->getPageSize()]]);
     $dataProvider->sort->attributes['status'] = ['asc' => ['status' => SORT_DESC], 'desc' => ['status' => SORT_ASC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['status' => $this->status]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text]);
     if ($this->created_at) {
         $interval = Yii::$app->current->getDateInterval($this->created_at);
         $query->andFilterWhere(['between', 'created_at', $interval[0], $interval[1]]);
     }
     return $dataProvider;
 }
예제 #8
0
        </div><!-- /.row -->
    </div><!-- /.container -->
</section>


<section id="news" class="section middle-padding hidden-sm hidden-xs">
    <div class="container">
        <div class="row">
            <!--div class="col-md-3">
                <div class="heading-line color-info big"></div>
                <h3 class="lighter no-padding-top">Новости</h3>
            </div><!--/.col-->
            <div class="col-md-12">
                <div class="row">
        			<?php 
foreach (\backend\modules\news\models\News::find()->where('publish_at < ' . Yii::$app->formatter->asTimestamp('now'))->orderBy('id DESC', 'publish_at DESC')->limit(4)->all() as $data) {
    ?>
                        <div class="col-md-3">
                            <span><?php 
    echo Html::decode($data->publish_at);
    ?>
</span>
                            <h4 class="lighter"><?php 
    echo Html::decode($data->title);
    ?>
</h4>
                            <p><?php 
    echo Html::decode($data->summary);
    ?>
</p>
                            <p><?php 
예제 #9
0
</div>




<section id="news" class="section middle-padding hidden-sm hidden-xs">
    <div class="container">
        <div class="row">
            <div class="col-md-3">
                <div class="heading-line color-info big"></div>
                <h2 class="lighter no-padding-top">Новости</h2>
            </div><!--/.col-->
            <div class="col-md-9">
                <div class="row">
        			<?php 
foreach (\backend\modules\news\models\News::find()->orderBy('id DESC')->limit(3)->all() as $data) {
    ?>
                        <div class="col-md-4">
                            <span><?php 
    echo Html::decode($data->publish_at);
    ?>
</span>
                            <h4 class="lighter"><?php 
    echo Html::decode($data->title);
    ?>
</h4>
                            <p><?php 
    echo Html::decode($data->summary);
    ?>
</p>
                            <p><?php 
예제 #10
0
    <div class="container">
        <div class="row">
            <div class="col-md-8">
                <?php 
echo $content;
?>
            </div>
            
            <div class="col-md-3 col-md-offset-1 hidden-sm hidden-xs">
                <div class="sidebar">
                    
                    <div class="widget">
                        <h3 class="widget-title">Новости</h3>
                        <div class="list-group shadow-1">
                            <?php 
foreach (\backend\modules\news\models\News::find()->orderBy(['publish_at' => SORT_DESC, 'id' => SORT_DESC])->limit(3)->all() as $data) {
    ?>
                                <?php 
    echo HTML::a(Yii::$app->formatter->asDate($data->publish_at, 'dd.MM.yyyy') . '<br/>' . $data->title, ['news/view', 'alias' => $data->alias], ['class' => 'list-group-item']);
    ?>
                            <?php 
}
?>
                        </div>
                    </div> 
                </div>
            </div> 
        </div> 
    </div> 
</div> 
예제 #11
0
 /**
  * @return News
  */
 public function getNews()
 {
     return $this->hasOne(News::className(), ['id' => 'news_id']);
 }