Reputation: 1
I have tried a few ways to do this but can't get any thing to work. My issue is that I want to pass a parameter from my module to a variable and output it in my html, through the default.php file.
Here is my config in the xml:
<config>
<fields name="params">
<fieldset name="basic">
<field name="prod_price"
type="text"
size="50"
label="Product Price"
description="Enter the product price" />
</fieldset>
</fields>
</config>
I think this is okay as it appears in the back-end.
My mod_helloworld.php file is simple and include a helper.php require, see below:
defined('_JEXEC') or die;
// Include the syndicate functions only once
require_once dirname(__FILE__) . '/helper.php';
$hello = modHelloWorldHelper::getHello($params);
$mydata = modHelloWorldHelper::getMydata($params);
require JModuleHelper::getLayoutPath('mod_helloworld');
$document = JFactory::getDocument();
$document->addStyleSheet('modules/mod_helloworld/css/style.css');
$document->addScript('modules/mod_helloworld/js/test.js');
I think this is okay, the variables are all returning values.
My helper.php file is as below:
class ModHelloWorldHelper
{
public static function getHello($params)
{
return 'Hello, World!';
}
public static function getMydata($params)
{
return 'Hello, World! ';
}
}
I then echo these variable in my default.php and they output fine. What I think I need to do is to get the $params variable somehow and reference the prod_price but I can't seem to do it. I am a beginner with creating modules so excuse any obvious errors. If the getMyData function could collect the params then I could perhaps output them but I am not sure where to put code?
Kind regards,
James
Upvotes: 0
Views: 1416
Reputation: 349
suppose http://examples.com/index.php?prod_price=20
You can receive that data in your module via
$price = JFactory::getApplication()->input->get('prod_price',0);
it will receive post or get request.
Upvotes: 1