CPagination generates wrong url

Hi there!

I recently added the following rule to the URL manager:


'<controller:\w+>/<id:\d+>/<action:\w+>'=>'<controller>/<action>'

This means if I have an url like this:


index.php/user/10/reviews

then it will be parsed as the route: ‘user/reviews’ with GET parameter ‘id’ being ‘10’. That works.

Now I added a CGridView to my page and the navigation links are broken:


	'pagination' => array(

		'pageSize' => 10,

		'route' => 'user/'.$id.'/AjaxDetails',

	),

The urls of the navigation buttons are: index.php/user/10/AjaxDetails/page/2 and it should be: index.php/user/10/AjaxDetails?page=2

I managed to debug all the way down and I found why the parameters added with ‘/’:


CUrlManager.php -> createUrlDefault($route,$params,$ampersand)

...

	if($this->appendParams)

	{

		$url=rtrim($url.'/'.$this->createPathInfo($params,'/','/'),'/');

		return $route==='' ? $url : $url.$this->urlSuffix;

	}

...

Here $this->appendParams is TRUE and it should be false. Docs: http://www.yiiframework.com/doc/api/1.1/CUrlManager#appendParams-detail

I can’t figure out how to make this work. Any suggestion would be appreciated!

UPDATE:

This one would be okay but not in the desired url format:


	'pagination' => array(

		'pagesize' => 10,

		'route' => 'user/AjaxDetails',

		'params' => array(

			'userId' => '10'

		)

	),

would generate:


index.php/user/AjaxDetails?userId=10&page=2

The desired URL format is:


index.php/user/10/AjaxDetails?page=2

Anybody? Any help would be great!

I recently encountered a similar issue, and I ended up overriding my SiteController’s createUrl method. There I ‘manually’ created some urls. Ie.:




public function createUrl($route, $params=array(), $ampersand='&'){

    if (array_key_exists('page',$params) /* && some other condition*/) return /*a custom URL*/ ;

    //this was in the original method  

    if($route==='')

                $route=$this->getId().'/'.$this->getAction()->getId();

           else if(strpos($route,'/')===false)

                $route=$this->getId().'/'.$route;

           if($route[0]!=='/' && ($module=$this->getModule())!==null)

                $route=$module->getId().'/'.$route;

           return Yii::app()->createUrl(trim($route,'/'),$params,$ampersand);            

}



It’s not very pretty but it works.