public function actionView($id) { $model = Article::findOne($id); Article::updateAllCounters(['times' => 1], ['id' => $id]); return $this->render('view', ['model' => $model]); }
/** * Finds the Article model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Article the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Article::findOne($id)) !== null) { $data = $model->getTags()->all(); if ($data) { $tags = []; foreach ($data as $row) { $tags[] = $row->tag; } $model->tags = implode(',', $tags); } return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }