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

XF 2.0 Access url params

katsulynx

Well-known member
#1
Is there a way to access the URL parameters from a place where this information is not accessible by default? Stuff like the thread_id from the URL for example.
 

Chris D

XenForo developer
Staff member
#2
The thing to bear in mind is there are two things involved in parameter collection from input. There's the Router parameter bag and there's the input filterer which can pull input from $_GET parameters or the $_POST body etc.

For the latter you can just do:
PHP:
$threadId = \XF::app()->inputFilterer()->filter('thread_id', 'uint');
To inspect the parameter bag of a URL is a bit more involved but still fairly simple:
PHP:
$routePath = \XF::app()->request()->getRoutePath();
$routeMatch = \XF::app()->router('public')->routeToController($routePath);
$parameterBag = $routeMatch->getParameterBag();

$threadId = $parameterBag->thread_id;
 

Chris D

XenForo developer
Staff member
#4
As a sort of side note, the parameter bag code is actually very similar to what we use to convert a thread URL to a thread ID for the purposes of the move/copy posts inline mod stuff. If you look at the bottom of the Thread repository, you will see a similar method, though that method actually gets the route path from a URL rather than the current request.