Video Lesson: Load data using a collection in Magento

Load data using a collection in Magento

This is premium content

Only available to enrolled or University students.
Join today to unlock all lessons in this course.

Load data using a collection in Magento

Learn how to load Magento blog post data using a collection in a ViewModel with dependency injection.

Lesson Content

Our data fetching logic is completely out of the template and in the ViewModel, but let’s take it a step further and fetch the real blog post data from the database.

Just like other Magento classes, the Post class is a regular class and has access to everything provided by the framework, such as dependency injection. We need an instance of our post collection class, so create a constructor with public function __construct() and pass in a new private dependency for the Collection class from Macademy\Blog\Model\ResourceModel\Post\Collection.

We’ll name this variable $collection...

Premium content

Enroll to unlock the full content and all course materials.

Maggie

Hey, I'm Maggie! πŸ‘‹

Ask me anything.

Want to chat with Maggie?

Enroll in this course for AI tutor access.

Comments

Join the discussion!

Comments

Want to comment on this lesson?

Enroll in this course to leave comments.