What is the use of pagefactory in Magento 2?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite












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();










share|improve this question



















  • 2




    Pagefactory is used to initialize the layout.
    – Ansar Husain
    Sep 5 at 6:12
















up vote
3
down vote

favorite












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();










share|improve this question



















  • 2




    Pagefactory is used to initialize the layout.
    – Ansar Husain
    Sep 5 at 6:12












up vote
3
down vote

favorite









up vote
3
down vote

favorite











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();










share|improve this question















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();







magento2 magento-2.2.5 object-manager factory pagefactory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 5 at 6:30









Amrit Pal Singh

699522




699522










asked Sep 5 at 5:57









Bhakti Thakkar

32412




32412







  • 2




    Pagefactory is used to initialize the layout.
    – Ansar Husain
    Sep 5 at 6:12












  • 2




    Pagefactory is used to initialize the layout.
    – Ansar Husain
    Sep 5 at 6:12







2




2




Pagefactory is used to initialize the layout.
– Ansar Husain
Sep 5 at 6:12




Pagefactory is used to initialize the layout.
– Ansar Husain
Sep 5 at 6:12










4 Answers
4






active

oldest

votes

















up vote
5
down vote



accepted










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();





share|improve this answer




















  • Thank you sir, and could you help me one more time. what is postfactory.
    – Bhakti Thakkar
    Sep 5 at 7:26

















up vote
2
down vote













Unlike Magento 1.x in magento 2 introduces factories which are used to set and get data of given object. best practice is, instead of using object manager use factories.



Like that Magento perform all operations systematically without changing the flow of request. so if any module overriding the functionality should have latest data.






share|improve this answer



























    up vote
    2
    down vote













    Page factory is used to create a page result by initializing the layout. Page factory create the response object in execute()



    public function execute()

    return $this->pageResultFactory->create();



    When you return a page result object from execute method, you’re telling Magento to kick off the standard layout handle XML file page rendering.






    share|improve this answer



























      up vote
      2
      down vote













      Magento2 uses the Factory Method Design Pattern which states that define and an interface for creating an object, but let subclasses decide which class to instantiate. Factory method design pattern lets a class defer instantiation to subclasses.



      Factories are service classes that instantiate non-injectable classes, that is, models that represent a database entity. They create a layer of abstraction between the ObjectManager and business code.

      They are an automatically generated class type.

      When you reference a factory in a class constructor, Magento’s object manager generates the factory class if it does not exist.
      You can go through the following articles for more details:



      • https://devdocs.magento.com/guides/v2.2/extension-dev-guide/factories.html

      • https://alanstorm.com/magento_2_object_manager_instance_objects/





      share|improve this answer




















        Your Answer







        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "479"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        convertImagesToLinks: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













         

        draft saved


        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f240856%2fwhat-is-the-use-of-pagefactory-in-magento-2%23new-answer', 'question_page');

        );

        Post as a guest






























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        5
        down vote



        accepted










        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();





        share|improve this answer




















        • Thank you sir, and could you help me one more time. what is postfactory.
          – Bhakti Thakkar
          Sep 5 at 7:26














        up vote
        5
        down vote



        accepted










        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();





        share|improve this answer




















        • Thank you sir, and could you help me one more time. what is postfactory.
          – Bhakti Thakkar
          Sep 5 at 7:26












        up vote
        5
        down vote



        accepted







        up vote
        5
        down vote



        accepted






        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();





        share|improve this 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();






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 5 at 6:25









        Ansar Husain

        1,236217




        1,236217











        • Thank you sir, and could you help me one more time. what is postfactory.
          – Bhakti Thakkar
          Sep 5 at 7:26
















        • Thank you sir, and could you help me one more time. what is postfactory.
          – Bhakti Thakkar
          Sep 5 at 7:26















        Thank you sir, and could you help me one more time. what is postfactory.
        – Bhakti Thakkar
        Sep 5 at 7:26




        Thank you sir, and could you help me one more time. what is postfactory.
        – Bhakti Thakkar
        Sep 5 at 7:26












        up vote
        2
        down vote













        Unlike Magento 1.x in magento 2 introduces factories which are used to set and get data of given object. best practice is, instead of using object manager use factories.



        Like that Magento perform all operations systematically without changing the flow of request. so if any module overriding the functionality should have latest data.






        share|improve this answer
























          up vote
          2
          down vote













          Unlike Magento 1.x in magento 2 introduces factories which are used to set and get data of given object. best practice is, instead of using object manager use factories.



          Like that Magento perform all operations systematically without changing the flow of request. so if any module overriding the functionality should have latest data.






          share|improve this answer






















            up vote
            2
            down vote










            up vote
            2
            down vote









            Unlike Magento 1.x in magento 2 introduces factories which are used to set and get data of given object. best practice is, instead of using object manager use factories.



            Like that Magento perform all operations systematically without changing the flow of request. so if any module overriding the functionality should have latest data.






            share|improve this answer












            Unlike Magento 1.x in magento 2 introduces factories which are used to set and get data of given object. best practice is, instead of using object manager use factories.



            Like that Magento perform all operations systematically without changing the flow of request. so if any module overriding the functionality should have latest data.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 5 at 6:03









            Naveed

            1,7331212




            1,7331212




















                up vote
                2
                down vote













                Page factory is used to create a page result by initializing the layout. Page factory create the response object in execute()



                public function execute()

                return $this->pageResultFactory->create();



                When you return a page result object from execute method, you’re telling Magento to kick off the standard layout handle XML file page rendering.






                share|improve this answer
























                  up vote
                  2
                  down vote













                  Page factory is used to create a page result by initializing the layout. Page factory create the response object in execute()



                  public function execute()

                  return $this->pageResultFactory->create();



                  When you return a page result object from execute method, you’re telling Magento to kick off the standard layout handle XML file page rendering.






                  share|improve this answer






















                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    Page factory is used to create a page result by initializing the layout. Page factory create the response object in execute()



                    public function execute()

                    return $this->pageResultFactory->create();



                    When you return a page result object from execute method, you’re telling Magento to kick off the standard layout handle XML file page rendering.






                    share|improve this answer












                    Page factory is used to create a page result by initializing the layout. Page factory create the response object in execute()



                    public function execute()

                    return $this->pageResultFactory->create();



                    When you return a page result object from execute method, you’re telling Magento to kick off the standard layout handle XML file page rendering.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 5 at 6:29









                    Prince Patel

                    11.5k44067




                    11.5k44067




















                        up vote
                        2
                        down vote













                        Magento2 uses the Factory Method Design Pattern which states that define and an interface for creating an object, but let subclasses decide which class to instantiate. Factory method design pattern lets a class defer instantiation to subclasses.



                        Factories are service classes that instantiate non-injectable classes, that is, models that represent a database entity. They create a layer of abstraction between the ObjectManager and business code.

                        They are an automatically generated class type.

                        When you reference a factory in a class constructor, Magento’s object manager generates the factory class if it does not exist.
                        You can go through the following articles for more details:



                        • https://devdocs.magento.com/guides/v2.2/extension-dev-guide/factories.html

                        • https://alanstorm.com/magento_2_object_manager_instance_objects/





                        share|improve this answer
























                          up vote
                          2
                          down vote













                          Magento2 uses the Factory Method Design Pattern which states that define and an interface for creating an object, but let subclasses decide which class to instantiate. Factory method design pattern lets a class defer instantiation to subclasses.



                          Factories are service classes that instantiate non-injectable classes, that is, models that represent a database entity. They create a layer of abstraction between the ObjectManager and business code.

                          They are an automatically generated class type.

                          When you reference a factory in a class constructor, Magento’s object manager generates the factory class if it does not exist.
                          You can go through the following articles for more details:



                          • https://devdocs.magento.com/guides/v2.2/extension-dev-guide/factories.html

                          • https://alanstorm.com/magento_2_object_manager_instance_objects/





                          share|improve this answer






















                            up vote
                            2
                            down vote










                            up vote
                            2
                            down vote









                            Magento2 uses the Factory Method Design Pattern which states that define and an interface for creating an object, but let subclasses decide which class to instantiate. Factory method design pattern lets a class defer instantiation to subclasses.



                            Factories are service classes that instantiate non-injectable classes, that is, models that represent a database entity. They create a layer of abstraction between the ObjectManager and business code.

                            They are an automatically generated class type.

                            When you reference a factory in a class constructor, Magento’s object manager generates the factory class if it does not exist.
                            You can go through the following articles for more details:



                            • https://devdocs.magento.com/guides/v2.2/extension-dev-guide/factories.html

                            • https://alanstorm.com/magento_2_object_manager_instance_objects/





                            share|improve this answer












                            Magento2 uses the Factory Method Design Pattern which states that define and an interface for creating an object, but let subclasses decide which class to instantiate. Factory method design pattern lets a class defer instantiation to subclasses.



                            Factories are service classes that instantiate non-injectable classes, that is, models that represent a database entity. They create a layer of abstraction between the ObjectManager and business code.

                            They are an automatically generated class type.

                            When you reference a factory in a class constructor, Magento’s object manager generates the factory class if it does not exist.
                            You can go through the following articles for more details:



                            • https://devdocs.magento.com/guides/v2.2/extension-dev-guide/factories.html

                            • https://alanstorm.com/magento_2_object_manager_instance_objects/






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Sep 5 at 6:37









                            Anshu Mishra

                            4,47732351




                            4,47732351



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f240856%2fwhat-is-the-use-of-pagefactory-in-magento-2%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                這個網誌中的熱門文章

                                How to combine Bézier curves to a surface?

                                Carbon dioxide

                                Why am i infinitely getting the same tweet with the Twitter Search API?