/**
  * Finds the Page model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Page the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Page::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 2
0
 public function findByUrl($alias)
 {
     /* @var $model Page */
     $url = $alias;
     $urlList = [];
     $urlCheck = [];
     if (substr_count($url, '/')) {
         $urlList = explode('/', $url);
         $url = array_pop($urlList);
     }
     $model = Page::findOne(['alias' => $url]);
     $parents = $model->parents();
     foreach ($parents as $item) {
         $urlCheck[] = $item->alias;
     }
     if ($urlList == $urlCheck) {
         return $model;
     }
     return null;
 }