Пример #1
0
 public function actionBlog_item($year, $month, $day, $id)
 {
     $date = $year . $month . $day;
     $pattern = '#^[a-z\\d_-]+$#';
     if (!preg_match($pattern, $id)) {
         throw new BadRequestHttpException('Имеются запрещенные символы');
     }
     $item = Blog::find(['date' => $date, 'id_string' => $id]);
     if (is_null($item)) {
         throw new HttpException(404, 'Нет такой статьи');
     }
     $item->incViewCounter();
     $nearList = Blog::query()->select('id,header,id_string,image,view_counter,description,date_insert,date')->orderBy(['date_insert' => SORT_DESC])->andWhere(['not in', 'id', $item->getId()])->limit(3)->all();
     return $this->render(['item' => $item, 'nearList' => $nearList]);
 }
Пример #2
0
 public function actionIndex()
 {
     return $this->render(['items' => Blog::query()->orderBy(['date_insert' => SORT_DESC])->all()]);
 }