magento 2 page factory object code example

Example: magento 2 result page factory create object

app/code/Pbritka/HelloWorld/Controller/Page/Index.php
<?php

namespace Pbritka\HelloWorld\Controller\Page;

class Index extends \Magento\Framework\App\Action\Action {

    protected $_pageFactory;

    public function __construct(\Magento\Framework\View\Result\PageFactory $pageFactory,
                                \Magento\Framework\App\Action\Context $context) {
        $this->_pageFactory = $pageFactory;
        parent::__construct($context);
    }

    public function execute() {
        $page = $this->_pageFactory->create();
        return $page;
    }
}

Tags:

Php Example