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 ?


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 ? – Lachezar Raychev Mar 15 '16 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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