2

If I want to retrieve a single parameter from a component the code is pretty simple, example:

$app = JFactory::getApplication();

$params = $app->getParams('com_content');

echo $params->get('num_leading_articles');

This works though only if you know the exact name of the parameter you want to retrieve. Is there a way to get ALL params instead? Sometimes you may not know all the parameters of a component, how can you get a list of those params if that's the case?

I'm on Joomla! 3.4

  • 2
    did you try using print_r($params) ? This contains all the parameters of com_content component. – Liz. Mar 28 '16 at 5:14
  • getParams() returns the Params object with wich we use the get() method to retrieve a single parameter. The only property of this returned object is the separator path. Quite unconvenient, but considering the amount of parameters that can be set maybe it's an overkill (I would mostly use for debug or similar though, not in production). – Gruber Mar 28 '16 at 6:14
7

You can simply use the following:

$componentParams= JComponentHelper::getParams('com_content');

var_dump($componentParams);

This will provide an object like so:

object(Joomla\Registry\Registry)[175]
  protected 'data' => 
    object(stdClass)[503]
      public 'article_layout' => string '_:default' (length=9)
      public 'show_title' => string '1' (length=1)
      public 'link_titles' => string '1' (length=1)
      etc....

Because it's a protected object, you will when of course need to use Joomla's get() method to access it, like so:

$foo = $componentParams->get('show_title');

If you'd like to get the params without knowing the name of them or without using get(), you can use a foreach loop like so:

$componentParams = JComponentHelper::getParams('com_content');

foreach ($componentParams as $key => $val)
{
    echo $key . ' - ' . $val;
}

Hope this helps

  • if I have understood him right, I think he is after somehow getting in an array or something, all the params with a single function at once, without having to call the get() for each one... – FFrewin Mar 28 '16 at 17:16
  • @FFrewin - Updated ;) – Lodder Mar 28 '16 at 17:37
  • 1
    Gah I found the issue, fact is that for not better known reasons, the dump from J!Dump extension wasn't returning correctly the output in the first place (though could be due to the protected properties). A raw var_dump got me what I was looking for. – Gruber Mar 28 '16 at 21:41
  • Slightly OT, since I got issues with a tool I'm quite familiar with like J!Dump, is there any good alternative for it atm? I mostly develop with Firefox DEV, and Sublime Text. – Gruber Mar 28 '16 at 21:46
  • @Gruber - I personally hate it, but PHPStorm may be a better text editor as it has advanced debugging tools. – Lodder Mar 28 '16 at 22:33

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.