Magento – the use of pagefactory in Magento 2

factorymagento-2.2.5magento2object-manager

Although I refer some blog of pagefactory, I don't understand the use of page factory.

There is one code in the controller. Could you please explain to me how it works?

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

Best Answer

Pagefactory is used to initialize the layout.

Its working in magento2 same like as in magento1 was doing with below code

$this->_view->loadLayout();

 $this->_view->renderLayout();
Related Topic