public function actionView() { if (Yii::$app->request->get('alt_title')) { $str = Yii::$app->request->get('alt_title'); $article = Article::findOne(['alt_title' => $str]); if (!Yii::$app->user->isGuest) { $article->updateCounters(['click' => 1]); } //ogp.me Yii::$app->opengraph->title = $article->title; Yii::$app->opengraph->description = $article->anons; Yii::$app->opengraph->image = Yii::$app->request->baseUrl . $article->anons_img; return $this->render('view', ['data' => $article]); } else { return new BadRequestHttpException(); } }
/** * @return \yii\db\ActiveQuery */ public function getArticles() { return $this->hasMany(Article::className(), ['author_id' => 'id']); }
/** * 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) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getArticlesCount() { return $this->hasMany(Article::className(), ['category_id' => 'id'])->count(); }