UrlManager: Problem with url rules that contain a fixed query parameter

Hi All,

if I have an url rule that contain query parameter, that adding any other query parameter via createUrl will add a duplication ‘?’ in the url.

Eq. consider the following rule :

‘system-tools.html?download=true’=>‘prdouct/downloadSystemTool’

Now

$this->createUrl(‘product/downloadSystemTool’, array(‘track’=>0))

will generate system-tools.html?download=true?track=0

For this problem, you need to:

=> Use "?download=true" string as a URL suffix in custom URL rule.

protected/config/main.php


'urlManager'=>array(

        'urlFormat'=>'path',

        'rules'=>array(        

                'system-tools.html' => array('prdouct/downloadSystemTool', 'urlSuffix' => '?download=true'),

        ),

),

=> Make changes in CUrlManager.php file as below:

framework/web/CUrlManager.php


public function createUrl($manager,$route,$params,$ampersand){                

        if($this->parsingOnly)

                return false;


        if($manager->caseSensitive && $this->caseSensitive===null || $this->caseSensitive)

                $case='';

        else

                $case='i';


        $tr=array();

        if($route!==$this->route){

                if($this->routePattern!==null && preg_match($this->routePattern.$case,$route,$matches)){

                        foreach($this->references as $key=>$name)

                                $tr[$name]=$matches[$key];

                }

                else

                        return false;

        }


        foreach($this->defaultParams as $key=>$value){

                if(isset($params[$key])){

                        if($params[$key]==$value)

                                unset($params[$key]);

                        else

                                return false;

                }

        }


        foreach($this->params as $key=>$value)

                if(!isset($params[$key]))

                        return false;


        if($manager->matchValue && $this->matchValue===null || $this->matchValue){

                foreach($this->params as $key=>$value){

                        if(!preg_match('/\A'.$value.'\z/u'.$case,$params[$key]))

                                return false;

                }

        }


        foreach($this->params as $key=>$value){

                $tr["<$key>"]=urlencode($params[$key]);

                unset($params[$key]);

        }


        $suffix=$this->urlSuffix===null ? $manager->urlSuffix : $this->urlSuffix;


        $url=strtr($this->template,$tr);


        if($this->hasHostInfo){

                $hostInfo=Yii::app()->getRequest()->getHostInfo();

                if(stripos($url,$hostInfo)===0)

                        $url=substr($url,strlen($hostInfo));

        }


        if(empty($params))

                return $url!=='' ? $url.$suffix : $url;


        if($this->append)

                $url.='/'.$manager->createPathInfo($params,'/','/').$suffix;

        else{

                if($url!=='')

                        $url.=$suffix;


                if (strpos($suffix, "?") !== false) {                [b]// find question mark in suffix string[/b]        

                        $url.='&'.$manager->createPathInfo($params,'=',$ampersand);

                }

                else {

                        $url.='?'.$manager->createPathInfo($params,'=',$ampersand);

                }

        }

        return $url;

}

Hope this helps!

Thanks!