在parseurl CBaseUrlRule中返回控制器和动作

时间:2014-08-03 12:24:15

标签: php yii

我没有关注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;
        }

1 个答案:

答案 0 :(得分:0)

您必须返回控制器和要运行的操作。

例如,如果您的网址必须使用NewsController运行actionIndex,您将返回

return 'news/index';

Source

相关问题