Help - Search - Members - Calendar
Full Version: Using PluginData
Movable Type Community Forum > Additional Resources > Plugin Development and Usage
tsbalaban
This code works:

CODE
my $data = MT::PluginData->load ({plugin => 'my_plugin', key => 'my_options'});
if ($data)  {
   my $page_bgcolor = $data->data->{'page_bgcolor'};
   my $side_bgcolor = $data->data->{'side_bgcolor'};
}


This does not update my data and I've tried other ways of writing the hash. I've also looked at all the plugins that use PluginData. It must have worked once but I can't get it to update now. No error messages.

CODE
my $data = MT::PluginData->new;
$data->plugin ('my_plugin');
$data->key ('my_options');
$data->data ({
   page_bgcolor => $page_bgcolor,
   side_bgcolor => $side_bgcolor,
});
$data->save or die $data->errstr;


Any help appreciated.
staggernation
It looks like you're creating a new row with the same key instead of updating the existing row. Try something like this:
CODE
my $data = MT::PluginData->load ({plugin => 'my_plugin', key => 'my_options'});
if (!$data) {
   $data = MT::PluginData->new;
   $data->plugin ('my_plugin');
   $data->key ('my_options');
}
$data->data ({
   page_bgcolor => $page_bgcolor,
   side_bgcolor => $side_bgcolor,
});
$data->save or die $data->errstr;
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.