/** * Parses the user request. * @param CHttpRequest $request the request application component * @return string the route (controllerID/actionID) and perhaps GET parameters in path format. */ public function parseUrl($request) { if($this->getUrlFormat()===self::PATH_FORMAT) { $rawPathInfo=$request->getPathInfo(); $pathInfo=$this->removeUrlSuffix($rawPathInfo,$this->urlSuffix); foreach($this->_rules as $i=>$rule) { if(is_array($rule)) $this->_rules[$i]=$rule=Yii::createComponent($rule); if(($r=$rule->parseUrl($this,$request,$pathInfo,$rawPathInfo))!==false) return isset($_GET[$this->routeVar]) ? $_GET[$this->routeVar] : $r; } if($this->useStrictParsing) throw new CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".', array('{route}'=>$pathInfo))); else return $pathInfo; } else if(isset($_GET[$this->routeVar])) return $_GET[$this->routeVar]; else if(isset($_POST[$this->routeVar])) return $_POST[$this->routeVar]; else return ''; }
CUrlManager初始化的时候如果url格式(默认是get格式)如果是path格式,则通过配置中的rule数组创建路由规则对象,根据路由规则获取内部路由,当路由都不匹配的时候会根据设置的useStrictParsing参数决定抛出一个404错误合适返回$pathinfo。如果不是path格式的话,会通过$_GET或者$_POST返回r后面的参数作为路由。
关与path路由的获取和创建,YII社区中两幅图分析的很详细