service = $service; } /** * @throws NotFoundHttpException */ public function actionView() { $id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT); if (Yii::$app->request->isAjax && $id) { $banner = $this->findModel($id); $this->service->addView($banner); } } /** * @throws NotFoundHttpException */ public function actionClick() { $id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT); if (Yii::$app->request->isAjax && $id) { $banner = $this->findModel($id); $this->service->addClick($banner); } } /** * @param $id * @return Banner * @throws NotFoundHttpException */ protected function findModel($id): Banner { if (($model = Banner::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException('The requested banner does not exist.'); } }