/**
  * 
  * @param string|integer $id
  * @param boolean $throwExceptionIfNull
  * @return Article
  * @throws \yii\web\NotFoundHttpException
  */
 public static function getArticle($id, $throwExceptionIfNull = true)
 {
     if (is_numeric($id)) {
         $article = Article::find()->id($id)->one();
         if ($article) {
             return $article;
         }
     }
     if (is_string($id)) {
         $article = Article::find()->name($id)->one();
         if ($article) {
             return $article;
         }
     }
     if ($throwExceptionIfNull) {
         throw new \yii\web\NotFoundHttpException(static::t('Article Not Found.'));
     }
     return null;
 }
Example #2
0
 /**
  * 
  * @return \rhopress\models\ArticleQuery
  */
 public function getArticle()
 {
     $article = Article::buildNoInitModel();
     return $this->hasOne(Article::className(), [$article->guidAttribute => 'article_guid']);
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getArticles()
 {
     $article = Article::buildNoInitModel();
     return $this->hasMany(Article::className(), [$article->createdByAttribute => $this->guidAttribute])->inverseOf('user');
 }