use TYPO3\CMS\Core\Utility\GeneralUtility; // Link to the current script with no query parameters $url = GeneralUtility::linkThisScript(); echo $url; // Output: http://example.com/path/to/script.php // Link to the current script with some query parameters $params = ['foo' => 'bar', 'baz' => 'qux']; $url = GeneralUtility::linkThisScript('', false, $params); echo $url; // Output: http://example.com/path/to/script.php?foo=bar&baz=qux
namespace MyVendor\MyExtension\Controller; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; class MyController extends ActionController { public function indexAction() { // Get the current script URL with query parameters $params = ['pid' => $this->settings['pid']]; $url = GeneralUtility::linkThisScript('', false, $params); // Do something with the URL... } }In both examples, we're using the GeneralUtility class, which is part of the "core" package of TYPO3 CMS.