XF 2.0 Access url params

Lukas W.

Well-known member
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.
 
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;
 
The latter one is what I needed and working perfectly. Thanks a lot! That's saving me a lot of headache.
 
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.
 
Top Bottom