Thursday, April 12, 2012

How to get a URL variable in Joomla

If you want to get a variable from URL the command is simply

$id = JRequest::getVar('id');
It will give you the value of 'id' if its in your url like:

http://www.b4blinky.com/index.php?id=1

However if you don't have an 'id' var in URL it will return you NULL, so if you want to have a default value of let's say zero you can use this


$id = JRequest::getVar('id','0');

Especially useful when you want to have some default views etc.

No comments:

Post a Comment