Video Lesson: Create a ViewModel in Magento

Create a ViewModel in Magento

This is premium content

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

Create a ViewModel in Magento

Learn how to create a Magento ViewModel to fetch and pass post data from the database to templates.

Lesson Content

Before we can display data from the database in a template, we need to know how to generally pass data to a template. This is where the β€œViewModel” part of the Model-View-ViewModel-Controller architecture comes into play.

The ViewModel is an intermediary layer between the controller, data, and view layers. Data used to be set within controllers, but to make controllers smaller and add more flexibility, the ViewModel layer was added. This lets you call the same ViewModel from multiple areas without duplicating code while also slimming down the responsibility of controllers.

You can think...

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.