9

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?

  • I mean apart from using the Options button – COBIZ webdevelopment Apr 4 '15 at 19:09
  • If you aren't using the options button, how are you getting the value that you want to store? – David Fritsch Apr 5 '15 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. – COBIZ webdevelopment Apr 5 '15 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. – Søren Beck Jensen Apr 6 '15 at 10:56
15

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;
}
  • 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) – COBIZ webdevelopment Apr 5 '15 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 – GDP Apr 5 '15 at 13:24

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.