Craft CMS Asked on December 24, 2020
I’m trying to create an event from within a plugin. I’ve come up with the following:
$event = new Event(); // SolspaceCalendarElementsEvent;
$event->authorId = 1;
$event->calendarId = 5;
$event->name = 'Hello name';
$event->title = 'Hello title';
$event->startDate = new DateTime();
$event->endDate = new DateTime();
$event->allDay = true;
But I don’t understand how to actually save the event (e.g. $event->save()
). Am I on the right track or completely off? I couldn’t find anything on this in the docs.
I got help on Discord. The way to do it was Calendar::getInstance()->events->saveEvent($event);
Edit: DateTime
also needs to be replaced with Carbon()
Correct answer by Stian Karlsen on December 24, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP