Page 1 of 1

Loading language file & parameters from another component?

Posted: Sat Mar 20, 2010 9:50 pm
by ljk
Hello,

Is it possible to load the language file and component parameters from another component when executing code in another component? For example, I need to add code to component x, which is coming from component y. In the code added to component x it needs to get parameter values and language files from component y.

What code would I use to load the parameters from component y and access component y's language entries when I am executing code in component x?

Any help would be appreciated.

Re: Loading language file & parameters from another component?

Posted: Sun Mar 21, 2010 1:21 am
by jeffchannell
$otherlanguage =& JFactory::getLanguage();
$otherlanguage->load( 'com_othercomponent', JPATH_SITE );

and

$otherparams =& JComponentHelper::getParams( 'com_othercomponent' );

??

Re: Loading language file & parameters from another component?

Posted: Sun Mar 21, 2010 10:03 pm
by ljk
Hello,

Thank you for your help.

Next question, how do I access the component parameters. I tried:

Code: Select all

      $pos_params = & JComponentHelper::getParams('com_posuid');
      return $pos_params->get('e-commerce-detail6');
and this is what is in config.xml for com_posuid:

Code: Select all

    
<param type="text" name="e-commerce-detail6" label="Shopper Group ID" default="5" description="default: 5" class="" cols="3" rows="1"/>
So, I expected that I would get 5 returned, but I am getting nothing returned.

I really appreciate you help.

Thank you.

Re: Loading language file & parameters from another component?

Posted: Sun Mar 21, 2010 10:21 pm
by jeffchannell
Have you tried defining a default in your return?

Code: Select all

      $pos_params = & JComponentHelper::getParams('com_posuid');
      return $pos_params->get('e-commerce-detail6', 5);
You might also try fetching the params via the menu, as I believe that should have all of the params (including those that are overridden by that menu item).

Another option is to fetch them raw directly from the __components database table and feed them into a new JParameter instance ( http://api.joomla.org/Joomla-Framework/ ... meter.html ).

Re: Loading language file & parameters from another component?

Posted: Wed Mar 24, 2010 11:08 pm
by ljk
Hello,

Once again thank you for your help.

I figured out why I wasn't getting anything returned using:

Code: Select all

$pos_params = & JComponentHelper::getParams('com_posuid');
      return $pos_params->get('e-commerce-detail6');
It was because there was no parameters stored in the component params field yet. Once I saved the Parameters in the backend, then this worked great.

I continue reading the documentation for parameters and it has this statement:
Note that there is no need to define default attributes for the <param /> elements in the config.xml file, since the default values will already have been saved in the installation of the Component.
on this page: http://docs.joomla.org/Component_parameters.
Do you have to define the parameters in the config.xml file in the installation file for the component in order for the default values to get saved into the database? Or how do the default attributes get saved in the installation of the component. I obviously have missed something.

Thanks again, you have been so helpful. I really appreciate you taking the time to answer these newbie questions.