{"id":362292,"date":"2022-12-29T05:29:43","date_gmt":"2022-12-29T05:29:43","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=362292"},"modified":"2023-02-14T13:38:28","modified_gmt":"2023-02-14T13:38:28","slug":"what-is-pagefactory-in-magento-2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/","title":{"rendered":"What is PageFactory in Magento 2?"},"content":{"rendered":"\n<p>Page factory is used to create a page result by initializing the layout. Page factory creates the response object in execute() method for the controller.<\/p>\n\n\n\n<p>Specific resultPageFactory is an instance of&nbsp;<code><strong>\\Magento\\Framework\\View\\Result\\PageFactory<\/strong><\/code>&nbsp;and when calling create on that class it returns an instance &nbsp;<code><strong>\\Magento\\Framework\\View\\Result\\Page<\/strong><\/code>&nbsp;described above. When this is used and the result is returned it means that your action will return HTML. It has somehow a similar similar effect as&nbsp;$this-&gt;loadLayout();&nbsp;from Magento 1. When you call create on the&nbsp;<code>resultPageFactory<\/code>&nbsp;object it actually loads the layout.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">public function execute() \n{ \n    $objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n    $this-&gt;pageResultFactory = $objectManager-&gt;create(\\Magento\\Framework\\View\\Result\\PageFactory);\n    return $this-&gt;pageResultFactory-&gt;create(); \n}<\/pre>\n\n\n\n<p><strong>What is the factory in Magento 2?<\/strong><\/p>\n\n\n\n<p>As you know in OOP,\u00a0<strong>a factory method will be used to instantiate an object<\/strong>. In <a href=\"https:\/\/webkul.com\/magento-development\/\">Magento 2<\/a>, the Magento 2 Factory Object does the same thing. To instantiate a model object we will use automatic constructor dependency injection to inject a factory object, then use a factory object to instantiate the model object.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Page factory is used to create a page result by initializing the layout. Page factory creates the response object in execute() method for the controller. Specific resultPageFactory is an instance of&nbsp;\\Magento\\Framework\\View\\Result\\PageFactory&nbsp;and when calling create on that class it returns an instance &nbsp;\\Magento\\Framework\\View\\Result\\Page&nbsp;described above. When this is used and the result is returned it means that <a href=\"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":368,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-362292","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is PageFactory in Magento 2? - Webkul Blog<\/title>\n<meta name=\"description\" content=\"What is PageFactory in Magento 2? Page factory is used to create a page result by initializing the layout. Page factory creates the response object in execute() method for the controller.\" \/>\n<meta name=\"robots\" content=\"index, nofollow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is PageFactory in Magento 2? - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"What is PageFactory in Magento 2? Page factory is used to create a page result by initializing the layout. Page factory creates the response object in execute() method for the controller.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-29T05:29:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-14T13:38:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Anurag Jain\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anurag Jain\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/\"},\"author\":{\"name\":\"Anurag Jain\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c62926ca988352d74ad5c2e85fcd4a63\"},\"headline\":\"What is PageFactory in Magento 2?\",\"datePublished\":\"2022-12-29T05:29:43+00:00\",\"dateModified\":\"2023-02-14T13:38:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/\"},\"wordCount\":157,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/\",\"url\":\"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/\",\"name\":\"What is PageFactory in Magento 2? - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2022-12-29T05:29:43+00:00\",\"dateModified\":\"2023-02-14T13:38:28+00:00\",\"description\":\"What is PageFactory in Magento 2? Page factory is used to create a page result by initializing the layout. Page factory creates the response object in execute() method for the controller.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What is PageFactory in Magento 2?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c62926ca988352d74ad5c2e85fcd4a63\",\"name\":\"Anurag Jain\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e15e522c60de7a76ffd1efc2152f6d848fcd5c14ce27b1d30bac29701d4c9837?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e15e522c60de7a76ffd1efc2152f6d848fcd5c14ce27b1d30bac29701d4c9837?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Anurag Jain\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/anuragjain-magento209\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is PageFactory in Magento 2? - Webkul Blog","description":"What is PageFactory in Magento 2? Page factory is used to create a page result by initializing the layout. Page factory creates the response object in execute() method for the controller.","robots":{"index":"index","follow":"nofollow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"What is PageFactory in Magento 2? - Webkul Blog","og_description":"What is PageFactory in Magento 2? Page factory is used to create a page result by initializing the layout. Page factory creates the response object in execute() method for the controller.","og_url":"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2022-12-29T05:29:43+00:00","article_modified_time":"2023-02-14T13:38:28+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Anurag Jain","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Anurag Jain","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/"},"author":{"name":"Anurag Jain","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c62926ca988352d74ad5c2e85fcd4a63"},"headline":"What is PageFactory in Magento 2?","datePublished":"2022-12-29T05:29:43+00:00","dateModified":"2023-02-14T13:38:28+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/"},"wordCount":157,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/","url":"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/","name":"What is PageFactory in Magento 2? - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2022-12-29T05:29:43+00:00","dateModified":"2023-02-14T13:38:28+00:00","description":"What is PageFactory in Magento 2? Page factory is used to create a page result by initializing the layout. Page factory creates the response object in execute() method for the controller.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/what-is-pagefactory-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"What is PageFactory in Magento 2?"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c62926ca988352d74ad5c2e85fcd4a63","name":"Anurag Jain","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e15e522c60de7a76ffd1efc2152f6d848fcd5c14ce27b1d30bac29701d4c9837?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e15e522c60de7a76ffd1efc2152f6d848fcd5c14ce27b1d30bac29701d4c9837?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Anurag Jain"},"url":"https:\/\/webkul.com\/blog\/author\/anuragjain-magento209\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/362292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/368"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=362292"}],"version-history":[{"count":3,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/362292\/revisions"}],"predecessor-version":[{"id":368833,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/362292\/revisions\/368833"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=362292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=362292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=362292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}