setContent() vs $entry->getContent()->foo I'm a bit confused about the usage of these two. Let's say I want to create a new entry from a controller. For me, the nicer option would be to user something like this:

$entry = new EntryModel();
$entry-&gt;sectionId = 4;
$entry-&gt;typeId = 4;

$entry-&gt;setContent([
    'foo' =&gt; 'bar',
    'xyz' =&gt; '456', 
]);

craft()-&gt;entries-&gt;saveEntry($entry);


Somehow this is not working for me. Instead, I have to use the uglier version like this:

$entry = new EntryModel();
$entry-&gt;sectionId = 4;
$entry-&gt;typeId = 4;

$entry-&gt;getContent()-&gt;foo = 'bar';
$entry-&gt;getContent()-&gt;xyz = '123';

craft()-&gt;entries-&gt;saveEntry($entry);


Any ideas why the first example might be failing? Especially when working with more than two attributes, the first example would be way more easy to handle.
You should be using setContentFromPost() rather than setContent(), so that field types have a chance to prep the values that you are passing in.

See “What is getContent() / the ContentModel, and how do I use it to get and set custom field values?” for more info on how this stuff works.