O'Reilly logo

Magento 2 Developer's Guide by Branko Ajzele

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required