protected function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Collect posts issued in specific month
  */
 public function actionPostedInMonth()
 {
     $month = date('n', $_GET['time']);
     // 1 through 12
     $year = date('Y', $_GET['time']);
     // 2011
     if (isset($_GET['pnc']) && $_GET['pnc'] == 'n') {
         $month++;
     }
     if (isset($_GET['pnc']) && $_GET['pnc'] == 'p') {
         $month--;
     }
     $query = Article::find()->where(['status' => Article::STATUS_ENABLED])->andWhere(['>', 'created_at', $firstDay = mktime(0, 0, 0, $month, 1, $year)])->andWhere(['<', 'created_at', mktime(0, 0, 0, $month + 1, 1, $year)])->orderBy('updated_at DESC');
     $pages = new Pagination(['totalCount' => $query->count()]);
     $pages->pageSize = \Yii::$app->params['monthlyArchivesCount'];
     $materials = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('month', array('materials' => $materials, 'pages' => $pages, 'firstDay' => $firstDay));
 }
示例#3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::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, 'status' => $this->status, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'updated_at' => $this->updated_at]);
     if (Yii::$app->user->can('admin')) {
         $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     } elseif (Yii::$app->user->can('FIRM') && IS_BACKEND) {
         $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['=', 'created_by', Yii::$app->user->id])->andFilterWhere(['like', 'content', $this->content]);
     }
     return $dataProvider;
 }