Updating the Database for plugin settings I have another plugin development question.

I am now trying to learn how to work with the database.  To that extent, I have the following code:

On the templates/settings.html page I have the following code:

{% import "_includes/forms" as forms %}

{{ forms.radioGroup({
    label: "Radio Group Label"|t,
    instructions: "Radio Group Instructions"|t,
    name: 'radioGroupName',
    options:{ "option_1" : "option_1", "option_2" : "option_2"},
    value: settings.radioGroupName
}) }}


On the records/PluginNameRecord.php page, I have the following code:

&lt;?php
namespace Craft;

class PluginNameRecord extends BaseRecord
{
    public function getTableName()
    {
        return 'pluginname';
    }


    public function defineAttributes()
    {
        return array(
            'radioGroupName' =&gt; array(AttributeType::String, 'default' =&gt; 'option_1')
        );
    }

}


And here is the code for the models/PluginNameModel.php file (I don't know if this is relevant or not, but I'm including it just in case):

&lt;?php
namespace Craft;

class PluginNameModel extends BaseModel
{

    public function defineAttributes()
    {
        return array(
            'radioGroupName' =&gt; array(AttributeType::String, 'default' =&gt; 'option_1')
        );
    }
}


Now, I have tested this and it creates a table and column in mysql.  However, I cannot update the data in the database.  That is to say, if I select option_2 nothing happens in mysql.  The same default value of option_1 still shows up.

Can someone please let me know what I am doing wrong?  

Thanks,

Moshe
You don't need to create Records, Models or interact with the database to store your plugin settings – Craft handles this for you out of the box. Here's how:

In your main plugin file (PluginNamePlugin.php):

protected function defineSettings()
{
    return array(
        'radioGroupName' =&gt; array(AttributeType::String, 'default' =&gt; 'option_1')
    );
}

public function getSettingsHtml()
{
   return craft()-&gt;templates-&gt;render('pluginname/settings', array(
       'settings' =&gt; $this-&gt;getSettings()
   ));
}


At a glance, your settings template looks fine, and should be placed within the pluginname/templates/ directory (filename settings.html).

If you want to retrieve a setting somewhere else within your plugin's main class, you can do it like this:

$settings = $this-&gt;getSettings();
$radioGroupName = $settings-&gt;radioGroupName;


To read the settings outside the main plugin class, you'll first need to pull the plugin instance, like this:

$plugin = craft()-&gt;plugins-&gt;getPlugin('pluginName');
$settings = $plugin-&gt;getSettings();
...


If you want to retrieve your setting(s) for use in templates, you'll need to create a template Variable class for your plugin in order to expose the data. Here's a quick example for your use case (the following would go into the file pluginname/variables/PluginNameVariable.php:

class PluginNameVariable
{
    public function settings()
    {
        $plugin = craft()-&gt;plugins-&gt;getPlugin('pluginName');
        return $plugin-&gt;getSettings();
    }
}


...and in your template:

{% set settings = craft.pluginName.settings %}
{{ settings.radioGroupName }}


For more info on plugin settings, see the official docs on the subject: http://buildwithcraft.com/docs/plugins/plugin-settings