I am having trouble with update and writeContent. I have a controller that calls $page ->update with a few fields that need to be updated.
In the pages model I have a writeContent function that updates the database as shown in the database examples.
Writing to the database works but results in any of the fields that were not set through the update function to be empty.
The page object does have the correct data when I dump it from the writeContent method but the data object that the function receives has all fields and the ones that are not sent to the update function are all empty strings.
This erases all the existing data (except the updated field). I must be doing something wrong but I can’t figure out why the other fields are being set to empty strings.
The example setup is only for a single language site but you seem to be in a multi-language context. Therefore Kirby doesn’t fetch the correct data set before saving. What does your model look like?
No, it’s not about the child model, but about defining the translations instead of the content array, like in the example I linked to. You can also see it at work with more detail in my unpublished “users from database” recipe, although it is all about user content, but the principle is the same:
from line 960ff
I’ve always wanted to extend the Virtual Pages guide, but didn’t get round to it yet.