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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.