/** * Displays a single Job model. * @param integer $id * @return mixed * @throws NotFoundHttpException */ public function actionJobDetail($id) { $model = Job::findOne($id); if ($model === null) { throw new NotFoundHttpException('The requested page does not exist.'); } //update hits $cookieName = "job_" . Yii::$app->user->getId() . "_{$id}"; if (!Yii::$app->request->cookies->has($cookieName)) { //update hits $model->hits = ++$model->hits; $model->update(); //make a cookie $cookies = Yii::$app->response->cookies; $cookies->add(new \yii\web\Cookie(['name' => $cookieName, 'value' => $model->hits, 'expire' => time() + 86400 * 1])); } Yii::$app->view->title = $model->title; Yii::$app->view->params['breadcrumbs'][] = ['label' => Yii::t($this->module->id, ucfirst($this->module->id)), 'url' => ['index']]; return $this->render('job-detail', ['model' => $model]); }
/** * Finds the Job model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $_id * @return Job the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Job::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }