0

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.

3

NOT TESTED

  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]); – David A McInnis Nov 21 '14 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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