I have created a Model with a Resource model to it and a collection.

In MyModel I have defined the property

public $myProperty;

However, when I try to do

$myModel = $this->MyModuleFactory->create(['myProperty'=>5]);

The value of myProperty is always NULL. How can I set the $myProperty value to 5 ?


1 Answer 1


you need to add 'myProperty' to the constructor aslo

public function __construct(
    $myProperty = null; //because this is not a class instance make it default to null otherwise the object manager will not know what to do with it
   $this->myProperty = $myProperty;

and instantiate your class like this

$data = ['myProperty'=>5];
$this->MyModuleFactory->create(['data' => $data]);
  • ah, when i did $this->MyModuleFactory->create( ['myProperty'=>5]); it got set, the create(['data' => $data]) did not work ? Commented Mar 15, 2016 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.