Archived

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

From Joomla! Documentation

m
(Use API's quoting methods for multi-db compatibility)
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{JVer|1.6}}{{JVer|1.7}}
+
{{JVer|1.6}}{{JVer|1.7}}{{JVer|2.5}}
  
 
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 [[User:Rvsjoen/tutorial/Developing_an_MVC_Component/Part_15 | Part 15]] of the [[User:Rvsjoen/tutorial/Developing_an_MVC_Component | Developing an MVC Component]] tutorial.
 
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 [[User:Rvsjoen/tutorial/Developing_an_MVC_Component/Part_15 | Part 15]] of the [[User:Rvsjoen/tutorial/Developing_an_MVC_Component | Developing an MVC Component]] tutorial.
Line 11: Line 11:
 
      
 
      
 
         if ($type == 'install') {
 
         if ($type == 'install') {
             $db = &JFactory::getDBO();
+
             $db = JFactory::getDBO();
             $query = $db->getQuery(true);
+
             $query = $db->getQuery(true);
             $query->update('#__extensions');
+
             $query->update($db->quoteName('#__extensions'));
 
             $defaults = '{"param1":"value1","param2":"value2"}'; // JSON format for the parameters
 
             $defaults = '{"param1":"value1","param2":"value2"}'; // JSON format for the parameters
             $query->set("params = '" . $defaults . "'");       // Single-quote the parameter list
+
             $query->set($db->quoteName('params') . ' = ' . $db->quote($defaults));
             $query->where("name = '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();
            }
 
 
         }  
 
         }  
 
     }
 
     }
Line 26: Line 25:
 
[[Category:Tips and tricks 1.6]]
 
[[Category:Tips and tricks 1.6]]
 
[[Category:Tips and tricks 1.7]]
 
[[Category:Tips and tricks 1.7]]
 +
[[Category:Tips and tricks 2.5]]

Revision as of 12:23, 11 February 2012

This page has been archived. This page contains information for an unsupported Joomla! version or is no longer relevant. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Joomla 1.6Joomla 1.7Joomla 2.5

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();
       } 
   }