Advertisement

Get id from URL Topic is solved

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
hcraig
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Fri Mar 10, 2023 1:14 pm

Get id from URL

Post by hcraig » Fri Mar 10, 2023 1:30 pm

Hi,

I am trying to get the id from the url

My url is: http://localhost/site1/?detail4=31
I am trying to extract only the 31 from the url, so far I have used below:

Code: Select all

<?php
defined('_JEXEC') or die('Restricted Access');

use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Router\Route;

$uri = Uri::getInstance();
$uri->toString(array('scheme','host','port','path','query', 'fragment'));
echo  "Page URI is: " . $uri->toString() . "<br>";
echo  "Scheme: " . $uri->getScheme() . "<br> Host: " . $uri->getHost() . " <br> Path: " . $uri->getPath() ." <br> Query: " . $uri->getQuery() . " <br> Fragment: " . $uri->getVar("NOT SURE WHAT TO PUT HERE") ."<br>";

?>
With this I get:
Page URI is: http://localhost/site1/?detail4=31
Scheme: http
Host: localhost
Path: /site1/
Query: detail4=31
Fragment:

I am not sure what to add in the $uri->getVar("NOT SURE WHAT TO PUT HERE")

Thank you in advance for any assistance,
Craig

Advertisement
SharkyKZ
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3257
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Get id from URL

Post by SharkyKZ » Fri Mar 10, 2023 2:11 pm

Code: Select all

$uri->getVar('detail4');
If you need to take routing into account, use Joomla\Input\Input instead of Uri:

Code: Select all

$input = Joomla\CMS\Factory::getApplication()->getInput();
$input->get('detail4');

hcraig
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Fri Mar 10, 2023 1:14 pm

Re: Get id from URL

Post by hcraig » Fri Mar 10, 2023 3:00 pm

Hello SharkyKZ,

Thank you so much for quick response.

Regards,
Craig

Advertisement

Locked

Return to “Joomla! 4.x Coding”