コード例 #1
0
 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();
     }
 }
コード例 #2
0
ファイル: User.php プロジェクト: knyazushka/z34lot.new
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getArticles()
 {
     return $this->hasMany(Article::className(), ['author_id' => 'id']);
 }
コード例 #3
0
 /**
  * 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.');
     }
 }
コード例 #4
0
ファイル: Category.php プロジェクト: knyazushka/z34lot.new
 public function getArticlesCount()
 {
     return $this->hasMany(Article::className(), ['category_id' => 'id'])->count();
 }