1

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:

  1. Request Variable: Check the image attached for the output. Value saves in the admin menu but not able to fetch in frontend.

    • image

    enter image description here

    • 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');

  2. 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

    enter image description here

    • 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:

Get the menu item variable using Jinput

And this joomla documentation:

https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_a_variable_request_in_the_menu_type

1

I solved the problem by using (2) - Params Method . I was taking the Please select option value to be 0 in default.xml. The solution was to set it null as follows and it is worked:

<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="">Please select</option>
    </field>
  </fieldset>
</fields>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.