No default params after install

80 views
Skip to first unread message

Sven Schultschik

unread,
Oct 18, 2012, 2:10:49 AM10/18/12
to joomla-de...@googlegroups.com
Aloha,

I've played a bit around and installed a self made component through
discover and normale package install. Both times I need to go into
Options and push one time save, else the params are not in the extension
table. Which means I get an error on frontend, that $params is not
defined.

Why are the default values not set on installation?

Joomla 3.0.1

regards

Sven

Viet Vu

unread,
Oct 18, 2012, 3:21:40 AM10/18/12
to joomla-de...@googlegroups.com
I attempted to fix it but not have enough time to complete it.


In the meantime, make sure that your code has some default values when the params are not set


Sven

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.


subtextproductions

unread,
Oct 19, 2012, 12:43:40 PM10/19/12
to joomla-de...@googlegroups.com
You can use the installer script postflight and update methods to populate the component params. It would look something like this:

class com_mycomponentInstallerScript
{
function postflight($type, $parent){
if($type == "install"){
$params['var1'] = 'x';
$params['var2'] = 'y';
$params['var3'] = 'z';
$this->setParams( $params );
}
}
}

As to why the default values are not set on installation automatically, I'm pretty sure that's because we're just waiting for someone to put in the time and energy to make that happen. Maybe that someone is you in conjunction with Viet Vu?

Fritsch Services

unread,
Nov 8, 2012, 6:39:58 PM11/8/12
to joomla-de...@googlegroups.com
I stumbled upon this post while trying to fix this exact issue. It seems only to affect components since the config info is in a separate config.xml file that is never loaded during install. I have started to look at tweaking the installer.php getParams method to look for that file too, but have not gotten it to work yet.

In the time being, I could not find a "setParams" function that you could run automatically from that class, so instead of writing one, I opted to try the following method which loads the config.xml file into a JForm (probably should just load the XML, but I had this code sitting around so I ran with it for the moment).

if($type == "install"){
if(method_exists($parent, 'extension_root')) {
$configfile = $parent->getPath('extension_root').'/config.xml';
} else {
$configfile = $parent->getParent()->getPath('extension_root').'/config.xml';
}
if (file_exists($configfile)) {
$xml = file_get_contents($configfile);
$form = JForm::getInstance('installer', $xml, array(), false, '/config');
$params = array();
if ($form->getFieldset('component')) {
foreach ($form->getFieldset('component') as $field) {
$params[$field->__get('name')] = $field->__get('value');
}
}
$db = JFactory::getDBO();
$query = "UPDATE #__extensions SET params='".json_encode($params)."' WHERE element='".$parent->get('element')."'";
$db->setQuery($query)->query();
}
}

This would go in the postflight function as outlined in the above post.

subtextproductions

unread,
Nov 9, 2012, 2:57:05 PM11/9/12
to joomla-de...@googlegroups.com
This page has an excellent example of an installer script with getParams and setParams methods.

Reply all
Reply to author
Forward
0 new messages