コード例 #1
0
ファイル: MUrlRule.php プロジェクト: kintastish/mobil
 public function parseRequest($manager, $request)
 {
     $route = '';
     $params = [];
     $pathInfo = $request->getPathInfo();
     if ($pathInfo == '') {
         return false;
     }
     $parts = explode('/', $pathInfo);
     $next = self::CATEGORY_PART;
     //вначале всегда идет раздел
     $parent_id = 0;
     foreach ($parts as $p) {
         if ($p != '') {
             switch ($next) {
                 case self::CATEGORY_PART:
                     $this->_cat = Categories::findByAlias($p, $parent_id);
                     if ($this->_cat === null) {
                         throw new NotFoundHttpException('Страница не найдена');
                     }
                     if ($this->getHandlerType($this->_cat->handler) == MController::HANDLE_CAT) {
                         $next = self::CATEGORY_PART;
                         $parent_id = $this->_cat->id;
                     } else {
                         $next = self::RESOURCE_PART;
                     }
                     break;
                 case self::RESOURCE_PART:
                     $this->_res = Resources::findByAlias($p, $this->_cat->id);
                     if ($this->_res === null) {
                         throw new NotFoundHttpException('Страница не найдена');
                     }
                     $next = self::PARAM_PART;
                     break;
                 case self::PARAM_PART:
                     $this->_params[] = $p;
                     break;
             }
         }
     }
     $route = $this->_cat->handler;
     // Если раздел содержит всего один ресурс/подраздел и $show_single == 1, тогда покажем дочерний элемент
     // Если дочерний элемент подраздел и $show_single == 1 идем ниже и т.д.
     if ($this->_res == false) {
         $action = 'index';
         $params = ['id' => $this->_cat->id];
         if ($this->_cat->show_single) {
             while (count($this->_cat->subcategories) == 1 && $this->_cat->show_single == 1) {
                 $this->_cat = $this->_cat->subcategories[0];
             }
             $route = $this->_cat->handler;
             $params = ['id' => $this->_cat->id];
             if (count($this->_cat->resources) == 1 && $this->_cat->show_single) {
                 $action = 'view';
                 $params = ['id' => $this->_cat->resources[0]->id];
             }
         }
     } else {
         $action = 'view';
         $params = ['id' => $this->_res->id];
     }
     $route .= '/' . $action;
     return [$route, $params];
 }
コード例 #2
0
ファイル: PageController.php プロジェクト: kintastish/mobil
 protected function findModel($id)
 {
     if ($id != 0) {
         if (($model = Resources::findOne($id)) !== null) {
             return $model;
         }
     } else {
         if (($model = Categories::findByAlias('0', 0)->resources[0]) !== null) {
             return $model;
         }
     }
     throw new NotFoundHttpException('The requested page does not exist.');
 }