views:

285

answers:

2

Hi,

If I do a redirect in action as normal:

$this->redirect('@mypage?apple=1&banana=2&orange=3');

... Symfony produces the correct URL:

/something/something?apple=1&banana=2&orange=3

However, the following gets escaped for some bizarre reason:

$string = 'apple=1&banana=2&orange=3';
$this->redirect('@mypage?'.$string);

... and the following URL is produced:

/something/something?apple=1&banana=2&orange=3

Is there a way to avoid this escaping and have the ampersands appear correctly in the URL? I've tried everything I can think of and it's driving me mad. I need this for a situation where I'm pulling a saved query as a string from the database and would just like to latch it onto the URL. I'm aware that I could generate an array from the string and then generate a brand new URL from the array, but it just seems like a lot of overhead because of this silly escaping.

Thanks.

+1  A: 

When you say "appear correctly", you might be missing the fact that & is the 'correct' representation of the variable separator & in URLs - for well-formed X(HT)ML, & must be encoded as &

That said, the behaviour in your script is unusual in that you'd expect the same behaviour in both examples. I guess these aren't routing-specific parameters to your routing rule, although I would expect symfony as default to slashify your variables like this:

/something/something/apple/1/banana/2/orange/3

It's not some odd PHP setting that's interfering with your strings, is it?

EDIT: I've tested it with symfony 1.3.3, and it's slashifying the variables as I suggested. I'm inclined to think it's a PHP/Apache setting that's causing it. Check your php.ini file for the arg_separator.output setting.

Raise
@Raise: No unusual PHP settings or anything like that. By "appear correctly" I just mean proper ampersands that separate request parameters. Right now this "banana}={2}" which is totally wrong.
Tom
Slashifying... yeah that would go through the routing.yml associations. However, I've got 25 variables stringed together that I don't want to declare in routing but just want to keep as a GET query string for further manipulation.
Tom
Didn't really get resolved but closing this question / marking the above as accepted.
Tom
A: 

I believe this is your best bet.

$url = $this->getController()->genUrl('search/list');
$this->redirect($url.'?q='.$q.'&g='.$g);

This works fine for me (the &'s are not escaped to &amp)

mattsidesinger