Page 1 of 1

Custom module rawurlencode with CreateLink (cause by array)

Posted: Fri Nov 15, 2013 10:14 am
by Eric Pesser
Hi,

I currently have an error in a custom module.

I think CMSM API don't support arrays while generating urls.

My urls are pagination url from a search page. All links should be copied and so all parameters are needed.

Here is the call :

Code: Select all

$item->url = $this->CreateLink($id, 'my_list', $returnid, '', array_merge($params, array('pagination_page_number' => $item->index, 'pagination_page_limit' => $params['pagination_page_limit'])), '', true);
I've added a select/multiple in the search panel. So that now, $params contain an array.

This array causes a rawurlencode() warning because this funtion is waiting a string.

[removed by moderator]

Re: Custom module rawurlencode with CreateLink (cause by arr

Posted: Fri Nov 15, 2013 11:21 am
by guro
You may serialize your array before use array_merge. And unserialize in your module after processing cms core.

Re: Custom module rawurlencode with CreateLink (cause by arr

Posted: Fri Nov 15, 2013 12:13 pm
by Eric Pesser
guro wrote:You may serialize your array before use array_merge. And unserialize in your module after processing cms core.
Mmmh yes that could be a good workaround in this case, but for me, only a workaround. Not a real solution I think.

That should be a better solution if that core function does implement it don't you think?

Re: Custom module rawurlencode with CreateLink (cause by arr

Posted: Fri Nov 15, 2013 12:21 pm
by guro
Perhaps. Waiting for response from the core developers.

Re: Custom module rawurlencode with CreateLink (cause by arr

Posted: Fri Nov 15, 2013 12:27 pm
by Eric Pesser
Me too.

Thanks for your contribution, I did not think to serialisation.

Re: Custom module rawurlencode with CreateLink (cause by arr

Posted: Fri Nov 15, 2013 1:43 pm
by velden
Just out of curiosity: why don't you use a loop in YOUR code? I'd expect that would be better than changing core code.

Re: Custom module rawurlencode with CreateLink (cause by arr

Posted: Fri Nov 15, 2013 2:25 pm
by Eric Pesser
I should do this in my code, as guro told me, using serialization when a value is an array, use for this my own CreateLink/CreateFrontEndLink function. True.

But for me, passing an array by url is not really specific.

Changing the core would manage the case we have to put en array in the url.

Actually, this case gives an error.

This (w2msSearchRegionId is a select/multiple list) :

Code: Select all

&m6c29bw2msSearchRegionId[]=16399&m6c29bw2msSearchRegionId[]=16394&m6c29bw2msSearchRegionId[]
is what I get after form submit. Actually, CMSMS API don't allow me to make such a standard url. Normal?

So I think Core API must either split values like I did, or serialize array.