XF 2.2 Sorting link with params

FoxSecrets

Active member
I need to pass a string param to my page in order to sort table columns but no success.
How to correctly pass params in a link tag? Should url be configured?

TEMPLATE:
Code:
<a href="{{ link('my-page/sort', {'column': 'category'}, {'order': 'asc'}) }}" title="Sort by ASC"><i class="fas fa-sort-amount-up"></i></a>
 
Tried in a array but getting null, why? object(XF\Mvc\ParameterBag)#332 (1) { ["params":protected]=> array(0) { } }

Code:
<a href="{{ link('my-page/sort', [{'column': 'category'}, {'order': 'asc'}]) }}" title="Sort by ASC"><i class="fas fa-sort-amount-up"></i></a>

Code:
public function actionSort($params)
    {
        var_dump($params);
        $params = [
            'column' => $params->column,
            'order' => $params->order
        ];
        return $this->view('My\Class\Index', 'my_page_index', $params);
    }
 
Only route parameters are passed as the second argument to link and accessed via the ParameterBag. If you want to use arbitrary parameters, pass them as the third argument instead and they will be passed in the query string.

HTML:
<a href="{{ link('my-page/sort', null, {'column': 'category', 'order': 'asc'}) }}"><xf:fa icon="fa-sort-amount-up" title="Ascending sort" /></a>

You access GET parameters (query string values) the same as POST parameters:

PHP:
public function actionSort(ParameterBag $params): AbstractReply
{
   $input = $this->filter([
        'column' => 'str',
        'order' => 'str',
    ]);

    $viewParams = [
        'column' => $input['column'],
        'order' => $intput['order'],
    ];
    return $this->view('My\Page:Sort', 'my_page_sort', $viewParams);
}
 
Top Bottom