我创建了自己的类来扩展 CBaseUrlRule 来管理网站上的某种页面。结果类代码是
class HotelUrlRule extends CBaseUrlRule {
public function parseUrl($manager,$request,$pathInfo,$rawPathInfo) {
if(isset($_GET['id'])) {
if (($_GET['id'] != 0) && ($pathInfo == 'hotel')) {
return 'hotel/index';
}
}
return false;
}
public function createUrl($manager,$route,$params,$ampersand) {
if ($route == 'hotel/index') {
Yii::import('application.controllers.SearchController');
$searcher = new SearchController($this, NULL);
$hotelRaw = $searcher->actionGetHotelInformation($_GET['id']);
$hotelRaw = $hotelRaw['GetHotelInformationResult'];
$hotelName = $hotelRaw['Name'];
$hotelName = preg_replace('%(\s)%', '-', $hotelName);
return 'hotel/' . $hotelName;
}
return false;
}
}
parseUrl ($_GET['id'] != 0) && ($pathInfo == 'hotel') 中的条件返回 'true',createUrl ($route == 'hotel/index') 中的条件返回 'false' . $route 的 var_dump 是 'admin/auth'。
为什么会这样?有什么猜测吗?