我没有关注CBaseUrlRule
parseUrl
。文档说它返回控制器和操作,但我得到Unable to resolve the request "name".
,这样url.com/name,原始请求是url.com/module/controller/action?id=id&name=name
。所以createUrl
正在创建一些令人满意的外观网址,但它不会返回controller/action/id
。我绝对不认为我理解整个流程。当我parseurl
时,它会查看我创建的网址url.com/name
。如果是这样,它怎么能得到控制器和动作?
从CBaseUrlRule扩展
public $connectionID = 'db';
public function parseUrl($manager,$request,$pathInfo,$rawPathInfo)
{
if(preg_match('~^module/controller/action?id=(\d+)~',$pathInfo)){
$query_string = parse_url($pathInfo, PHP_URL_QUERY);
parse_str($query_string, $data);
$id = $data['id'];
$result = Yii::app()->{$this->connectionID}->createCommand()
->select('table_id')
->from('table')
->where('table_id=:id', array(':id'=>$id))
->queryRow();
if(!empty($result)) {
$_GET['id']=$id;
return ?;
//don't quiet understand this part? return what?
//I don't understand why some places they return id, then what happened to my controller and action?
}
}
return false;
}
答案 0 :(得分:0)