Actions

Difference between revisions of "Setting parameters to default on installation"

From Joomla! Documentation

(Remove 1.6 and 1.7 tags)
m
 
Line 15: Line 15:
 
             $defaults = '{"param1":"value1","param2":"value2"}'; // JSON format for the parameters
 
             $defaults = '{"param1":"value1","param2":"value2"}'; // JSON format for the parameters
 
             $query->set($db->quoteName('params') . ' = ' . $db->quote($defaults));
 
             $query->set($db->quoteName('params') . ' = ' . $db->quote($defaults));
             $query->where$db->quoteName('name') . ' = ' . $db->quote('com_XXX')); // com_XXX is your component  
+
             $query->where($db->quoteName('name') . ' = ' . $db->quote('com_XXX')); // com_XXX is your component  
 
             $db->setQuery($query);
 
             $db->setQuery($query);
 
             $db->query();
 
             $db->query();

Latest revision as of 07:41, 21 November 2013

When developing an component you can ensure that the `params` field of the `#__extensions` table is populated during the installation process by using the installation script file as described in Part 15 of the Developing an MVC Component tutorial.

Adding code similar to the following to the postflight() function within the script file will update `#__extensions` with the required parameters:

   function postflight($type, $parent)
   {
       // $parent is the class calling this method
       // $type is the type of change (install, update or discover_install)
   
       if ($type == 'install') {
           $db = JFactory::getDBO();
           $query = $db->getQuery(true);
           $query->update($db->quoteName('#__extensions'));
           $defaults = '{"param1":"value1","param2":"value2"}'; // JSON format for the parameters
           $query->set($db->quoteName('params') . ' = ' . $db->quote($defaults));
           $query->where($db->quoteName('name') . ' = ' . $db->quote('com_XXX')); // com_XXX is your component 
           $db->setQuery($query);
           $db->query();
       } 
   }