I am having some trouble when trying to create a new Entry in Craft3 via PHP. In Craft 2, I was able to do something like this:
$entry = new EntryModel();
$entry->getContent()->title = $name;
$entry->getContent()->answer = $answer;
$handle = "nameOfTheSectionIWantToSaveIn";
$entry->sectionId = craft()->sections->getSectionByHandle($handle)->id;
$save = craft()->entries->saveEntry($entry);
Before asking, I took some time to read through the Craft3 Class Reference and came across the namespace:
craft\elements
I have come to the conclusion(could be wrong) that I need to use something like the following:
use craft\elements\Entry;
$entry = new Entry();
However, I am a little confused as to where I go from here. I checked the available Craft Entry Public Methods and could not find a method like getContent(), which was used in Craft2. I did see a getContentTable(), but not sure if thats what I am looking for.
getContentyou just dosetFieldValue– Robin Schambach Jun 19 '18 at 04:56$entry->getErrors()like in Craft 2 – Robin Schambach Jun 22 '18 at 05:06