Beispiel #1
0
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|bool the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  * @throws NotFoundHttpException
  */
 public function parseRequest($manager, $request)
 {
     $this->currentLanguage = Language::getCurrent();
     $this->pathInfo = $request->getPathInfo();
     if ($this->pathInfo == $this->albumsRoute) {
         if ($this->disableDefault) {
             throw new NotFoundHttpException();
         }
         if (!empty($request->getQueryParams()['id'])) {
             $id = $request->getQueryParams()['id'];
             $album = GalleryAlbum::findOne($id);
             if (!$album) {
                 return false;
             }
             $translation = $album->getTranslation($this->currentLanguage->id);
             if ($translation) {
                 if (!empty($translation->seoUrl)) {
                     throw new NotFoundHttpException();
                 }
             }
         }
     }
     if (!empty($this->prefix)) {
         if (strpos($this->pathInfo, $this->prefix) === 0) {
             $this->pathInfo = substr($this->pathInfo, strlen($this->prefix));
         } else {
             return false;
         }
     }
     $this->initRoutes($this->pathInfo);
     if (!empty($this->prefix) && $this->routesCount == 1) {
         return [$this->albumsRoute, []];
     } else {
         if ($this->routesCount == 2) {
             $seoUrl = $this->routes[1];
             /* @var SeoData $seoData */
             $seoData = SeoData::find()->where(['entity_name' => GalleryAlbumTranslation::className(), 'seo_url' => $seoUrl])->one();
             if ($seoData) {
                 /* @var GalleryAlbum $album */
                 $album = GalleryAlbum::find()->joinWith('translations translation')->where(['translation.id' => $seoData->entity_id, 'translation.language_id' => $this->currentLanguage->id])->one();
                 if ($album) {
                     return [$this->albumsRoute, ['id' => $album->id]];
                 }
             }
         }
     }
     return false;
 }
 public function run()
 {
     return $this->controller->render('list', ['albums' => GalleryAlbum::find()->all()]);
 }