I keep getting a server error when attempting to save data to a table field. This is the code I am using test data insertion. (251 is a valid enteryId)

    $entry = craft()->entries->getEntryById(251, $localeId = null);
    $arr = array('col1' => 'some sku', 'col2' => 'This is a big fat description', 'col3' => 495.00, 'col4' => 0);
    $arr = json_encode($arr);
    $entry->getContent()->gistDistribution = $arr;
    $success = craft()->entries->saveEntry($entry);

This is my error:

Internal Server Error
Illegal string offset 'sku'

Note: sku is a column name in my table field.


1 Answer 1



  1. I think you can just add an array to gistDistribution, it will get json_encoded before saving.
  2. I think you'd have to set the variable like this:

    $arr[0] = array(...);

That way, you provide a multidimensional array, which is what a table needs.

  • I have tested your recommendations. It works. To add a row. $arr[0] = array(...); $existingDistributions = $entry->getContent()->gistDistribution; array_push($existingDistributions, $arr[0]); Commented Nov 21, 2014 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.