How do I update a column value in my custom plugin with a simple controller? I have a custom element type with its own table 'pluginname_entries'. I am trying to find a way to "dummy proof" changing the plugins status. So I came up, aka stole from the Events element type, with the idea of clicking a button that triggers a controller action - similar to the following example to delete my element types entry:

actionDelete()

/**
 * Deletes an entry.
 */
public function actionDelete()
{
    $this-&gt;requirePostRequest();

    $entryId = craft()-&gt;request-&gt;getRequiredPost('entryId');

    if (craft()-&gt;elements-&gt;deleteElementById($entryId))
    {
        craft()-&gt;userSession-&gt;setNotice(Craft::t('Entry deleted.'));
        $this-&gt;redirectToPostedUrl();
    }
    else
    {
        craft()-&gt;userSession-&gt;setError(Craft::t('Couldn’t delete entry.'));
    }
}


I love the concept or a quick way to delete or update the entry, more specifically the entry custom status, with a simple click of a button. So I came up with this:

actionDeny()

/**
 * Changes an entry to denied.
 */
public function actionDeny()
{
    $this-&gt;requirePostRequest();

    $status = PluginStatus::Denied;

    $entryId = craft()-&gt;request-&gt;getRequiredPost('entryId');

    $query = craft()-&gt;db-&gt;createCommand()
        -&gt;select('id, status')
        -&gt;from('entries')
        -&gt;where(array(
            'id' =&gt; $entryId
        ))-&gt;queryRow();

    if ($query == null) {
        craft()-&gt;userSession-&gt;setError(Craft::t('Unable to deny the entry.'));
    }
    else {
        craft()-&gt;userSession-&gt;setNotice(Craft::t('The entry was denied.'));
    }

}


That works as intended, notifying the user but of course doesn't actually update the status column to the new value, is there a better way to handle this? Maybe more of a "Craft" way?
You are currently performing a SELECTinstead of an UPDATE so no data will be updated.

I'm guessing that entryId is the primary key of the record you are trying to update? If so, I would suggest you find the record to make sure it exists, update its attributes (status) and then save it.

// PluginController
public function actionDeny()
{
    $this-&gt;requirePostRequest();

    $status  = PluginStatus::Denied;
    $entryId = craft()-&gt;request-&gt;getRequiredPost('entryId');

    if (craft()-&gt;pluginName-&gt;updateStatus($entryId, $status)
    {
        craft()-&gt;userSession-&gt;setError(Craft::t('Unable to deny the entry.'));
    }
    else
    {
        craft()-&gt;userSession-&gt;setNotice(Craft::t('The entry was denied.'));
    }
}

// PluginService
public function updateStatus($id, $status)
{
    $record = PluginRecord::model()-&gt;findById($id);

    if ($record)
    {
        $record-&gt;setAttribute('status', $status);

        return $record-&gt;save();
    }
    else
    {
        throw new Exception(Craft:t('No record was found with id {id}', array('id' =&gt; $id));
    }
}


Unless I'm missing something, that should be about all you need.

@selvinortiz