• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 2.0 How to get all the inputs from the URL in an array

abdfahim

Active member
#1
I am designing a page with a PHP callback function. How can I collect all the GET parameters from the URL?

I know how to get each parameter separately, but I want to get all in an array in a single go, if possible

For example, for a page like this: pages/my-page/?param1=asd&param2=fgh&param3=vbn
Code:
public static function myPage(\XF\Pub\Controller\AbstractController $controller, \XF\Mvc\Reply\AbstractReply &$reply)
{       
    $params = $controller->request()->filter('param1','string');
}
 

abdfahim

Active member
#2
Also, I am wondering how to access $results in a template once it is returned from the callback function

Code:
public static function myPage(\XF\Pub\Controller\AbstractController $controller, \XF\Mvc\Reply\AbstractReply &$reply)
{       
    $viewParams = [
            'timeline' => $results
    ];
    $reply->setPageParams($viewParams);
}
 

Chris D

XenForo developer
Staff member
#3
I am designing a page with a PHP callback function. How can I collect all the GET parameters from the URL?

I know how to get each parameter separately, but I want to get all in an array in a single go, if possible

For example, for a page like this: pages/my-page/?param1=asd&param2=fgh&param3=vbn
Code:
public static function myPage(\XF\Pub\Controller\AbstractController $controller, \XF\Mvc\Reply\AbstractReply &$reply)
{    
    $params = $controller->request()->filter('param1','string');
}
PHP:
public static function myPage(\XF\Pub\Controller\AbstractController $controller, \XF\Mvc\Reply\AbstractReply &$reply)
{     
    $params = $controller->filter([
        'param1' => 'str',
        'param2' => 'str',
        'param3' => 'str'
    ]);
}
Also, I am wondering how to access $results in a template once it is returned from the callback function

Code:
public static function myPage(\XF\Pub\Controller\AbstractController $controller, \XF\Mvc\Reply\AbstractReply &$reply)
{    
    $viewParams = [
            'timeline' => $results
    ];
    $reply->setPageParams($viewParams);
}
PHP:
public static function myPage(\XF\Pub\Controller\AbstractController $controller, \XF\Mvc\Reply\AbstractReply &$reply)
{   
    $viewParams = [
        'timeline' => $results
    ];
    $reply->setParams($viewParams);
}
That would then be accessed in a template with {$timeline}.
 

abdfahim

Active member
#4
Oh, thanks a lot.

I checked \XF\Mvc\Reply\AbstractReply class where I found setPageParams, not setParams. Also my IDE (PhpStorm) shows no method as setParams().

Anyway, issue solved, thank a lot, as always.