Creating new entities

There are three different flavors, if we might call them that, by which we can set property (field and attribute) values on our entity. They all lead to the same result. The following few code snippets can be copied and pasted into our Crud class execute method for testing, simply by replacing /* CRUD Code Here */ with one of the following code snippets:

//Simple model, creating new entities, flavour #1 $department1 = $this->departmentFactory->create(); $department1->setName('Finance'); $department1->save(); //Simple model, creating new entities, flavour #2 $department2 = $this->departmentFactory->create(); $department2->setData('name', 'Research'); $department2->save(); //Simple model, creating new entities, flavour #3 $department3 ...

Get Magento 2 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.