XF 2.1 [SOLVED] buildLink() not appending query strings data

asprin

Active member
I've the following in the controller:
PHP:
$viewParams = [
            'href' => $this->buildLink('fantasy/fc-events', ['fmode'=>'abc', 'fstatus'=>'def'])
        ];

return $this->view('AFC:EventManagement', 'myTemplate', $viewParams);

And inside myTemplate.html is the following:
HTML:
{{$href}}

This prints out the following:
/xen/index.php?fantasy/fc-events/

whereas the expectation is:
/xen/index.php?fantasy/fc-events/&fmode=abc&fstatus=def

What am I missing here?
 
The third parameter is for query string parameters. The second parameter is for route data used for building route links.

So you just need to change the code to the following:

PHP:
$viewParams = [
            'href' => $this->buildLink('fantasy/fc-events', null, ['fmode'=>'abc', 'fstatus'=>'def'])
        ];

return $this->view('AFC:EventManagement', 'myTemplate', $viewParams);

Route data set to null, and your query string parameters moved to the third argument.
 
The third parameter is for query string parameters. The second parameter is for route data used for building route links.
I could have sworn I had tried putting null as second parameter and it didn't work earlier but now it does. I guess you posting the answer did the trick :p
 
Back
Top Bottom