How to get component parameters?

前端 未结 8 1686
萌比男神i
萌比男神i 2020-12-24 11:35

I have a problem here and just cant solve it :-/

I am developing an Joomla component with backend. In the backend I set a parameter, the dashboardId, bu

相关标签:
8条回答
  • 2020-12-24 12:21

    It is simular to J.T. Blum answer, but in Joomla 3.x JRequest is depricated. It is another way to get the apllication's params.

        $app = JFactory::getApplication();
        $input = $app ->input;
        $componentName = $input ->get('option');
        $params = JComponentHelper::getParams($componentName);
        print_r($params);
    
    0 讨论(0)
  • 2020-12-24 12:23

    Since version 3.1 Joomla is in process to deprecate all J classes, matter effect, version 4.0 will deprecate almost all J classes, the recommended way from now on to retrieve components param is either calling the entire namespace function:

    Joomla\CMS\Component\ComponentHelper::getParams('com_dashboard')->get('dashboardID');
    

    or, if you are working on a model, you can call use keyword in order to import the file and use the class down in the document, like

    use Joomla\CMS\Component\ComponentHelper;
    
    function myFunction() {
        $param = ComponentHelper::getParams('com_dashboard');
        $dashboardID = $param->get('dashboardID');
    }
    
    0 讨论(0)
  • 2020-12-24 12:26

    Helper Function to get Params Object in all Joomla Versions 1.5 / 2.5 /3.x

    class myCompoHelper{
    
        public static function getParams($option)
        {
    
            if (version_compare(JVERSION, '1.5', 'g'))
            {
                $application = JFactory::getApplication();
                if ($application->isSite())
                {
                    $params = $application->getParams($option);
                }
                else
                {
                    jimport('joomla.application.component.helper');
                    $params = JComponentHelper::getParams($option);
                }
            }
            else
            {
                jimport('joomla.application.component.helper');
                $params = JComponentHelper::getParams($option);
            }
            return $params;
        }
    
    }
    
    $params=myCompoHelper::getParams('com_mycomponent');
    echo $params->get('myParamName',null);
    
    0 讨论(0)
  • 2020-12-24 12:27

    Similar to the answer provided by LoboX, I'd recommend using the component helper to get component parameters:

    jimport('joomla.application.component.helper'); // Import component helper library
    $params = JComponentHelper::getParams(JRequest::getVar('option')); // Get parameter helper (corrected 'JRquest' spelling)
    $params->get('parameter_name'); // Get an individual parameter
    

    The JRequest::getVar('option') returns your component's name with the com_ prefix. Aside from that, it looks like you're trying to mix a little bit of 1.5/1.6 syntax into your configuration file. If you haven't seen it yet, try reading through the 2.5 version of the documentation. I hope that helps!

    0 讨论(0)
  • 2020-12-24 12:28
    $app = JFactory::getApplication('site');
    $componentParams = $app->getParams('com_example');
    $param = $componentParams->get('paramName', defaultValue);
    
    0 讨论(0)
  • 2020-12-24 12:31

    I had the same problem and the solution was this:

    $input = JFactory::getApplication()->input;
    $parametername = $input->getInt('parametername');
    echo $parametername;
    

    This is the name of a parameter in the default.xml in the views tmpl folder. here is the xml

    <?xml version="1.0" encoding="utf-8"?>
    <metadata>
        <layout title="Offers">
             <message>This is a component in order to display offers</message>
        </layout>
        <state>
            <name>name</name>
                <description>description</description>
    
            <url addpath="/administrator/components/com_component/elements">
                <param name="category_id" section="com_component" type="categoriesmenu"  value_field="category_name" label="COM_COMPONENT_CATEGORY_FIELD_SELECT_TITLE" description="COM_COMPONENT_CATEGORY_FIELD_SELECT_TITLE_DESC" />
            </url>
        </state>
    
        <fields name="request" >
            <fieldset name="request" addfieldpath="/administrator/components/com_component/models/fields">
                <field name="parametername" type="category"
                    label="category"
                    required="true"
                    description="Perigrafh"
                />
            </fieldset>
        </fields>
    
    
    </metadata>
    
    0 讨论(0)
提交回复
热议问题