Video Lesson: Create an object with a factory using dependency injection in Magento

Create an object with a factory using dependency injection in Magento

This is premium content

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

Create an object with a factory using dependency injection in Magento

Learn Magento 2 dependency injection by creating Page objects with PageFactory in a controller.

Lesson Content

So far, we’ve just used var_dump and die to output data to the screen, but you’ll only ever really be doing this when debugging code. You’ll almost always want to instead return something like a page response object.

Let’s remove all of the existing class properties, along with the contents of the execute method. We can then also remove all of the unused class imports.

Here’s the controller after cleaning it up:

<?php

declare(strict_types=1);

namespace Macademy\Blog\Controller\Post;

use Magento\Framework\App\Act...

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.