service = $service; } 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 ); } } 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 ); } } protected function findModel($id): Banner { if (($model = Banner::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException('The requested banner does not exist.'); } }