This is the code I copied from MagePlaza.
class Index extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory)
{
$this->_pageFactory = $pageFactory;
return parent::__construct($context);
}
public function execute()
{
return $this->_pageFactory->create();
}
}
How we will decide that here we need to use PageFactory and why we pass Magento\Framework\App\Action\Context in the constructor.
Can anyone help me out this please?