10

To retreive a param I use:

$myparam = JComponentHelper::getParams('com_mycomponent')->get('myparam'); 

But what is the right method to store a component's param?

4
  • I mean apart from using the Options button Commented Apr 4, 2015 at 19:09
  • If you aren't using the options button, how are you getting the value that you want to store? Commented Apr 5, 2015 at 4:00
  • Don't really understand your question. From any location, in another components controller for example, I would like to set a new value to some other components param. Commented Apr 5, 2015 at 5:16
  • You could try to build a component using component-creator.com and view the code it generates when adding parameters to your component. Commented Apr 6, 2015 at 10:56

1 Answer 1

16

Many of our component's parameters depend on external conditions, so we need to periodically change them with some overnight processing. Here's the code we use (adapted for use with com_content).

// Load the current component params. $params = JComponentHelper::getParams('com_content'); // Set new value of param(s) $params->set('show_title', 1); // Save the parameters $componentid = JComponentHelper::getComponent('com_content')->id; $table = JTable::getInstance('extension'); $table->load($componentid); $table->bind(array('params' => $params->toString())); // check for error if (!$table->check()) { echo $table->getError(); return false; } // Save to database if (!$table->store()) { echo $table->getError(); return false; } 
2
  • 1
    Thanks. This looks very great! So I was not overlooking an existing method, it really needs some extra code indeed. I'll markt your answer GOOD asap, when I have tested it. (But since you're already using this, It probably is the right answer anyway) Commented Apr 5, 2015 at 13:14
  • 1
    Happy to help...can't keep up with the Joomla versions as well as I'd like, so there may well be a method, but this one has been working for us for awhile now...cheers Commented Apr 5, 2015 at 13:24

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.