How to pass variables or parameters from one Joomla article to another using DirectPHP?
Written by kksou   
Thursday, 30 June 2011

One of the most commonly asked questions for DirectPHP is: how do you pass a variable or parameter from one Joomla page to another?

In a plain PHP page, you can easily do this with:

page1.php?var1=value1

But try this in a Joomla article using DirectPHP. Most likely you will be directed somewhere else and your article will not appear.


Demo

Let's see a quick demo of this in action first.

var1 and var2 below are currently empty:

var1 = 
var2 =

The codes that produce the above are:

<?php
echo "var1 = ".$_GET['var1']."<br />";
echo "var2 = ".$_GET['var2']."<br />";
?>

Now click on this link which contains: http://www.kksou.com/php-gtk2/index.php?option=com_content&Itemid=1&id=2013&lang=en&task=view&var1=value1&var2=value2

Did you see that the two parameters above have been populated with 'value1' and 'value2' respectively?

Explanation

If you take a look at the URL of your Joomla articles, you should see that each article is identified by 4 key parameters:

  • option: This is the component used to display the article, which is com_content
  • Itemid: This is the menu id associated with this article. It determines which modules will be displayed together with this article.
  • id: This is the unique id of the article.
  • task: This tells the component that you want the article to be displayed when its value is view.

For this article that you are viewing right now, you can see that the 4 values are:

  • option: com_content
  • Itemid: 1
  • id: 2013
  • task: view

If you are using languages other than English, you might also need to pass in the parameter lang.

Conclusion

To pass variables or parameters from one Joomla article to another, in addition to the parameters you want to pass, you must also remember to pass in the following variables:

  1. option
  2. Itemid
  3. id
  4. task
  5. lang (if you are using languages other than English)

For example: http://www.kksou.com/php-gtk2/index.php?option=com_content&Itemid=1&id=2013&lang=en&task=view&var1=value1&var2=value2


 

Add comment


Security code
Refresh

< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2012. kksou.com. All Rights Reserved