Hey, i've been trying ChatGPT to help me create a custom plugin for a simple like-button in GRAV. I want to store the data in a flex-directory called "likes", there is one test-entry in it already. Properties are:
published (copied from the contacts demo), masked_ip, datetime, page, hash.
where hash is $hash = md5($ip . $page_route);
I'm having problems creating a new flex-object from the plugin and checking if the hash already exists. I want to prevent visitors from liking multiple times. I know this is not a guarantee, but i don't want to use cookies or sessions.
//Define the Flex Objects directory
$flexdir = $this->grav['locator']->findResource('user://data/flex-objects/likes.json');
if (!$flexdir) {
throw new \RuntimeException('Likes flex-directory not found');
}
if ($flexdir) {
$this->grav['log']->info('dir exists');
$this->grav['log']->info('page: '.$page_route);
$object = new FlexObject($flexdir,[
'published' => 1,
'masked_ip' => $ip_masked,
'datetime' => $timestamp,
'page' => $page_route
]);
// Save the object to the Flex Directory
$flexdir->save('likes/' . $hash, $object);
}
The logfile says:
grav.CRITICAL: Grav\Framework\Flex\FlexObject::__construct(): Argument #1 ($elements) must be of type array, string given, called in ... line 131
This line is: 'page' => $page_route
Any ideas? I tried YAML instead of flex objects before, but didn't work. Not sure if YAML is good for storing arrays of the same structure.
Thanks in advance.