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...
Join the discussion!
Comments
Want to comment on this lesson?
Enroll in this course to leave comments.