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=426&catid=24&id=2013&lang=en&view=article&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.
- view: This tells the component that you want the article 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
- view: 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:
- option
- Itemid
- id
- view
- 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&iew=article&var1=value1&var2=value2
Comments
i am using directPHP IN joomla2.5, i SET no filtering. Its jumping form FORM page to action page,but nothing is showing when I echo $_POST['var1'], and i want to interact with database also, can you pleas help me?
You said "when I launch the command below".
What is that "command" that you are referring to?
Also, for "the page is not found 404 error", what is the complete url that you see at the top of the browser?
Regards,
/kksou
Is the command in the field in a table with URL
http://www.ciuhet.net/index.php/index.php?option=com_content&Itemid=258&id=52&lang=en&task=view&mth=January&d_id=2&year_id=12
'index.php?option=com_content&Itemid=258&id=52&lang=en&task=view&mth=$a[$z]&d_id=$d_id&year_id=$year_id'>$tout[$n]
I am using:
$itemid =JRequest::getVar('Itemid');
$id = JRequest::getVar('id');
to get the itemid en id, thats working but how do I pass the variables with directPHP in the INPUT statement?
Regards,
Hans
You can pass any parameters. The key thing is whether your module can receive that.
So you need to look at your module how it retrieves those parameters. E.g. if it uses $_GET, then you can use DirectPHP to pass the variables as method=GET. However, if it uses $_POST, then you have to use method=POST.
Warm Regards,
/kksou
but i tried to pass variables as above but it doesn't work.
I typed the url in the browser. the page with article shows up, but not my variable.
did I miss any setting in Joomla?
Regards
Marc
RSS feed for comments to this post