I have added a request variable in the menu for my component but it is not working. Following are 2 ways by which I tried:
Request Variable: Check the image attached for the output. Value saves in the admin menu but not able to fetch in frontend.
- image
default.xml :
<fields name="request"> <fieldset name="request"> <field name="gid" type="sql" label="FIELDLABEL" description="FIELDDESC" query="SELECT * FROM #__component_list" value_field="name" key_field="id"> <option value="0">Please select</option> </field> </fieldset> </fields>
models/filename.php:
$gid
returns null$gid = JFactory::getApplication()->input->get('gid');
Params Method: Check the image attached. Value saves in admin menu and can access the variable in model by the following code. But, in admin menu the saved value is not binding in the field. Can't understand why, though
gid
value changes in database each time I save the menu.- image
default.xml:
<fields name="params"> <fieldset name="advanced"> <field name="gid" type="sql" label="FIELDLABEL" description="FIELDDESC" query="SELECT * FROM #__component_list" value_field="name" key_field="id"> <option value="0">Please select</option> </field> </fieldset> </fields>
model/filename.php: Returns the correct result in frontend.
$menuParam = JFactory::getApplication()->getParams(); $gid = $menuParam->get('gid');
Also, referred this question but couldn't find possible answer:
And this joomla documentation:
https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_a_variable_request_in_the_menu_type