Yii Multidimensional Params With Createurl

I’ve been extremely confused about urlManager::createUrl()!!! I want to use it to build an url like this one:




$url = 'http:://localhost/myapp/mycontroller/myaction/?related[key1]=1&related[key2]=2';



That means support params as multidim array. If your try to call for example:




$array_of_keys = array(

    'key1' => 1,

    'key2' => 2

);

$url = Yii::app()->createUrl('mycontroller/myaction', array('id' => $array_of_keys));



These will generate a PHP Warning: urlencode() expects parameter 1 to be string, array given. After googlin around I found a Yii issue http://code.google.com/p/yii/issues/detail?id=737 (and related git issues). It report just the same bug I’m exposing here but It also says that it’s closed (resolved if you look in the changelog) but that’s not true!!!

PS: this situation has been created because I NEED to handle composite primary key in the url together with other params. Since the "multidim support" should be already there I would like to use this functionality to handle composites pks.

I understand now when it occurs (tnx XDebug). For everyone that had the same prolem can follow my solution. Inside the urlManager::createUrl() method there is a loop that its started whenever $this->params is not empty. This is the case when you have url rules like




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

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

$this->params will be populated since id:\d+ is catched. That will start a loop that will use urlencode that generate the warning.

So if you remove those rules you will have the chance to support composite primary keys in your urls like so:

View




Yii::app()->controller('view', array('id' => $model->primaryKey)),



Controller




public function actionView(array $id) { ... }



So that you can also have an automatic bind of params into your actions!!! Hope this can be useful to somebody.