コード例 #1
0
ファイル: PostSearch.php プロジェクト: NullRefExcep/yii2-blog
 /**
  * @param $slug
  * @return array|null|Post
  * @throws NotFoundHttpException
  */
 public function findBySlug($slug)
 {
     /** @var PostQuery $query */
     $query = Post::find();
     $query->published()->bySlug($slug);
     if (($model = $query->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }