Guest User

Untitled

a guest
Jun 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. <?php
  2.  
  3. $section = Craft::$app->sections->getSectionByHandle('journalArticles');
  4. $entryTypes = $section->getEntryTypes();
  5. $entryType = reset($entryTypes);
  6.  
  7. $entry = new Entry([
  8. 'sectionId' => $section->id,
  9. 'typeId' => $entryType->id,
  10. 'fieldLayoutId' => $entryType->fieldLayoutId,
  11. 'authorId' => 1,
  12. 'title' => 'My Entry',
  13. 'slug' => 'my-entry',
  14. 'postDate' => new DateTime(),
  15. ]);
  16.  
  17. $entry->setFieldValues([
  18. 'journalTitle' => 'Hello'
  19. ]);
  20.  
  21. $success = Craft::$app->elements->saveElement($entry);
  22.  
  23. if(!$success) {
  24. echo "why";
  25. }
Add Comment
Please, Sign In to add comment