How to get the сollection of custom Magento 2 modules
Take your constructor and inject the model collection factory into it:
1 |
protected $mymodulemodelFactory; public function __construct( .... \[Namespace]\[Module]\Model\Resource\[Entity]\CollectionFactory $mymodulemodelFactory, ... ) { ... $this->mymodulemodelFactory = $mymodulemodelFactory; ... } |
It is possible to use it in any class method:
$collection = $this->mymodulemodelFactory->create();

More tips from Magento 2 Developer’s Cookbook
