Pass Array Parameter In Createurl

Hi, how can I pass an array parameter in createUrl.

Let’s say I’m creating a url :


Yii::app()->createUrl('site/action', array('id' => $ids))

where $ids is an array. So I want to have id[0]=1, id[1]=2 … and use these in my action $_GET[‘id’].

How can I do this? Right now, it’s giving me a 400 error. The URL looks like this:


www.website.com/site/action/id%5B0%5D/1/id%5B1%5D/2/

createUrl depends on your urlManager routes, could you paste them here? The defaults are made for scalar values, not arrays.

Maybe just use another key instead of ‘id’, like ‘ids’.

I think it would help if the [font="Courier New"]id[/font] param were not part of the route …

Edit: Wow, seems like I’ve been distracted for full ten minutes while posting this.

There are no rules written right now …

There is a possible fix. I pass the id parameter using implode(";",$ids) … so I will have the url like [code]www.website.com/site/action/id/1;2;3[code]

And the I explode the ids in my action. But here is my problem. If I have to pass 1000 ids, will that be a problem ? The url would be very long …

However, if anybody has a way of passing arrays, that would be great. I’m sure it has something to do with UrlRules.

Passing 1000 ids as an array would be even worse, you get 4 chars (id[]) for one id instead of just one (the separator). Anyway, if you’re thinking of passing so many ids maybe you could build some criteria condition instead?

For selecting multiple rows in a grid I use two modes: select some or select all with exceptions.

You are right, so I went another way. I’m gonna creat a search model, that has fields for filtering data, creating IN conditions to my CDbCriteria. And then I’m gonna return the correct models.

So the AJAX request will only contain the search model attributes, and not an array of correct ID’s.

Thank you!