コード例 #1
0
ファイル: Router.php プロジェクト: NareshChennuri/pyng
 public static function route($uri)
 {
     $parts = explode('/', trim($uri, '/'));
     $db = JO_Db::getDefaultAdapter();
     $request = JO_Request::getInstance();
     $query = $db->select()->from('url_alias');
     $get_controller = null;
     $get_action = null;
     if ($request->getController() != 'index' && in_array($request->getController(), WM_Modules::getControllers())) {
         $get_controller = $request->getController();
         if ($request->getAction() != 'index' && in_array($request->getAction(), WM_Modules::getControllerResources($get_controller))) {
             $get_action = $request->getAction();
         }
     }
     foreach ($parts as $part) {
         if (self::checkJsCss($part)) {
             continue;
         } elseif (in_array($part, self::$systems)) {
             continue;
         } elseif ($part == 'pinit.html') {
             JO_Request::getInstance()->setController('pinit')->setAction('index');
             continue;
         }
         $query->where('keyword = ?', $part);
         $results = $db->fetchRow($query);
         if ($results) {
             parse_str($results['query'], $data);
             foreach ($data as $key => $value) {
                 /*if($key == 'board_id' && !$request->getParam('user_id')) {
                 			continue;
                 		}*/
                 if ($request->getRequest($key)) {
                     // 						$request->setParams($key, $request->getRequest($key) . '_' . $value);
                     $request->setParams($key, $value);
                 } else {
                     $request->setParams($key, $value);
                 }
                 if ($results['route']) {
                     $call = explode('/', $results['route']);
                     $controller = 'index';
                     $action = 'index';
                     if (trim($call[0])) {
                         $controller = $call[0];
                     }
                     if (isset($call[1]) && trim($call[1])) {
                         $action = $call[1];
                     }
                     if ($get_controller) {
                         $controller = $get_controller;
                     }
                     if ($get_action) {
                         $action = $get_action;
                     }
                     $request->setController($controller)->setAction($action);
                 }
             }
         }
         $query->reset(JO_Db_Select::WHERE);
     }
 }