Yii URL格式化带来的翻页参数问题

'urlManager' => array(
            'urlFormat' => 'path',
            'appendParams' => false,//设置为false,使提交的search参数以?a=b&c=d的形式显示在url后面
            'showScriptName' => true,
            'rules' => array(
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            ),
        ),

问题:

1、使用zii.widgets.CListView列表显示,CListView默认使用CLinkPager

2、问题出现,搜索时,地址栏正确,为:http://host/index.php/default/index?a=b&c=d

  但是页面下方翻页按钮url为:http://host/index.php/default/index/a/b/c/d

  如果有值为空,url为http://host/index.php/default/index/a//c/d

  此时点翻页按钮,页面不跳转。复制url到新页面,页面空白

解决:API写的太笼统,实在看不懂,直接找源码

CUrlManager.php

 1 protected function createUrlDefault($route,$params,$ampersand)
 2     {
 3         if($this->getUrlFormat()===self::PATH_FORMAT)
 4         {
 5             $url=rtrim($this->getBaseUrl().'/'.$route,'/');
 6             if($this->appendParams)
 7             {
 8                 $url=rtrim($url.'/'.$this->createPathInfo($params,'/','/'),'/');
 9                 return $route==='' ? $url : $url.$this->urlSuffix;
10             }
11             else
12             {
13                 if($route!=='')
14                     $url.=$this->urlSuffix;
15                 $query=$this->createPathInfo($params,'=',$ampersand);
16                 return $query==='' ? $url : $url.'?'.$query;
17             }
18         }
19         else
20         {
21             $url=$this->getBaseUrl();
22             if(!$this->showScriptName)
23                 $url.='/';
24             if($route!=='')
25             {
26                 $url.='?'.$this->routeVar.'='.$route;
27                 if(($query=$this->createPathInfo($params,'=',$ampersand))!=='')
28                     $url.=$ampersand.$query;
29             }
30             elseif(($query=$this->createPathInfo($params,'=',$ampersand))!=='')
31                 $url.='?'.$query;
32             return $url;
33         }
34     }

第6行 $this->appendParams

API解释为:whether to append GET parameters to the path info part.

必应翻译:是否要追加到路径的参数信息的一部分。

果断在config/main.php中修改为false,问题解决。

 

列为看官,不看源码只读api,谁能明白这个设置原来是干这个的。坑爹的api解释

posted @ 2013-05-30 14:41  慧眼见真  阅读(796)  评论(0编辑  收藏  举报