I'm trying to set a parameter of a component. I have models->rules then the php rule. This seems to work fine. However when I try to set one of the component params it refuses to do it. I've looked around at questions and found what seems to be fairly standard way of working but I can't get it to work - I'm now using;

            $comparams = JComponentHelper::getParams('#__extensions');
            $comparams->set('your_param', "dev.com");
            $componentid = JComponentHelper::getComponent('com_comonentname')->id;
            $table = JTable::getInstance('extension');
            $table->bind(array('params' => $comparams->toString()));
            // check for error
            if (!$table->check()) {
                $this->setError('your_website_domain: check: ' . $table->getError());
                return false;
            // Save to database
            if (!$table->store()) {
                $this->setError('your_website_domain: store: ' . $table->getError());
                return false;

which I think is correct. It runs the code and when I put in debugging the query is correct. But once the save is complete the value remains unchanged. What am I doing wrong. I can't get the setter to work - is there some other block on the table.

**Update new methods tried.

So I've also now tried this:

            $jinput = JFactory::getApplication()->input;

            $foo = $jinput->get('jform', '', '');

            $foo['your_param'] = "dev.com";

            $varname = $foo['your_param'] ;

            $jinput->set($varname, "dev.com");

this again shows in debug it updates but then at some point they system reinstates the original value. For completeness I also tried:

            $componentid = JComponentHelper::getComponent('com_comonentname')->id;
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);

                ->where($db->quoteName('a.extension_id') . ' = '. $db->quote($componentid)) ;

            $results = $db->loadObjectList();

            foreach($results as $parameter){
                $compParams = json_decode($parameter->params);

            $compParams->your_param = "dev.com";

            $updatedParams = json_encode($compParams);

            $db = JFactory::getDbo();

            $query = $db->getQuery(true);

            $fields = array(
                $db->quoteName('params') . " = '" . $updatedParams."'"

            // Conditions for which records should be updated.
            $conditions = array(
                $db->quoteName('extension_id') . ' = '.$componentid



            $result = $db->execute();

Same as before something is reinstating the original value. So I can't think of any other way now to try to overcome the system.

  • Your first piece of code works fine for me. Although in JComponentHelper::getParams() you're supposed to pass the component name. Maybe more context is needed. Where is this code placed, how/when is triggered? – Sharky Jun 1 at 19:46
  • The code is in a model - it's triggered on save when updating the component configuration. – user1616338 Jun 1 at 20:04
  • Component global configuration is normally managed through com_config. Are you doing this in some different way? – Sharky Jun 1 at 21:34
  • @user just for your knowledge, you don't need to declare a table alias (a) in your first query (the select query). Because you are only accessing columns from one table, there is no ambiguity to address. Also, if you are going to toe the Joomla Coding Standards line, you should call quote() on your updated json string to wrap it in single quotes. – mickmackusa Jun 3 at 11:43
  • @user This is not an answer, but a thorough review of your mysql code block. Please digest the many refinements and compare to your posted code. 3v4l.org/YMs3s If you would like a full breakdown of what I did and why, you can post a new question and I can itemize my suggestions. – mickmackusa Jun 3 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.