Inserting data into a table fieldtype via plugin? I'm trying to import data from another database into a 'table' fieldtype via a plugin, and have a couple questions.

When setting the content on the EntryModel, are there any methods to assist in setting the rows and/or columns, or do I need to just format the data as a string in the expected format?

    $entry-&gt;getContent()-&gt;setAttributes(array(
        'tableFieldHandle' =&gt; '[{"col1":"data","col2":"data"}]'
    ));


Secondly, what's the recommended method to prepare strings for a table field (i.e. so as to escape or encode double and single quotes)?
The thing to keep in mind here is that a table field contains a simple JSON string. So you can (and should) use PHP's native json_encode function to prepare your data...

// Your data will be an array of arrays:
$tableData = array(
    array(
        "col1" =&gt; "data",
        "col2" =&gt; "data",
    )
);

// Then simply encode it when you set your field value:
$entry-&gt;getContent()-&gt;setAttributes(array(
    'tableFieldHandle' =&gt; json_encode($tableData)
));


This will also solve any string escaping concerns for you!