{"id":455496,"date":"2024-08-01T10:52:24","date_gmt":"2024-08-01T10:52:24","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=455496"},"modified":"2025-05-19T13:21:31","modified_gmt":"2025-05-19T13:21:31","slug":"create-module-in-magento-2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/","title":{"rendered":"How to Create a Module in Magento 2"},"content":{"rendered":"\n<p>Learn how to create a module in Magento 2 Step by Step guide with CRUD operation<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Module Registration<\/h3>\n\n\n\n<p>Creating <a href=\"https:\/\/store.webkul.com\/Magento-2.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 extensions<\/a> involves several structured steps to ensure that the module is properly defined, registered, and activated &#8211; <a href=\"https:\/\/webkul.com\/blog\/module-registration-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Module Registration<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Create Routing<\/h3>\n\n\n\n<p>The complete module&#8217;s flow depends on processing URL requests and router classes which are responsible for matching and processing those requests &#8211; <a href=\"https:\/\/webkul.com\/blog\/magento-2-routing\/\" target=\"_blank\" rel=\"noreferrer noopener\">Routing<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Create Database Tables and related files<\/h3>\n\n\n\n<p>Before developing the frontend part of the module, let\u2019s create a database table. <\/p>\n\n\n\n<p>We will be developing a simple&nbsp;blog manager module&nbsp;so we need a table to save the blog data &#8211; <a href=\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Create Database Table<\/a><\/p>\n\n\n\n<p>To perform the CRUD (Create, Read, Update, Delete) operations we have to create these three classes (i.e. Model, Resource Model, and Collection) for each table &#8211; <a href=\"https:\/\/webkul.com\/blog\/magento-2-model-resource-model-collection\/\" target=\"_blank\" rel=\"noreferrer noopener\">Model, Resource Model, and Collection<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: CRUD operations<\/h3>\n\n\n\n<p>Now let\u2019s come back to frontend. Earlier we created a controller where I wrote a \u201cHello World\u201d statement to show you that the controller is working. To show HTML content we use .phtml files in Magento2 &#8211; <a href=\"https:\/\/webkul.com\/blog\/magento-2-layout-and-templates\/\" target=\"_blank\" rel=\"noreferrer noopener\">Layout and Template<\/a><\/p>\n\n\n\n<p>Now that we have created a nice form let\u2019s use it to save some data in the table. &#8211; <a href=\"https:\/\/webkul.com\/blog\/magento-2-save-data-with-form-validation\/\" target=\"_blank\" rel=\"noreferrer noopener\">Save Data with Form Validation<\/a><\/p>\n\n\n\n<p>After saving the data we will fetch it and show it in a table format &#8211; <a href=\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/\" target=\"_blank\" rel=\"noreferrer noopener\">Fetch Data and Show<\/a><\/p>\n\n\n\n<p>To now work on editing and updating we need to first understand filtering and sorting of data &#8211; <a href=\"https:\/\/webkul.com\/blog\/magento-2-filter-and-sorting\/\" target=\"_blank\" rel=\"noreferrer noopener\">Filter and Sort<\/a><\/p>\n\n\n\n<p>Editing and Updating the data &#8211; <a href=\"https:\/\/webkul.com\/blog\/edit-update-data-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Edit and Update<\/a><\/p>\n\n\n\n<p>Finishing the CRUD with the delete option &#8211; <a href=\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Delete operation<\/a><\/p>\n\n\n\n<p>Kickstart your projects with the experienced\u00a0<a href=\"https:\/\/webkul.com\/magento-development\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 development company<\/a> that has been crafting innovative Adobe Commerce extensions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to create a module in Magento 2 Step by Step guide with CRUD operation Step 1: Module Registration Creating Magento 2 extensions involves several structured steps to ensure that the module is properly defined, registered, and activated &#8211; Module Registration Step 2: Create Routing The complete module&#8217;s flow depends on processing URL requests <a href=\"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":204,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-455496","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>How to Create a Module in Magento 2 Step By Step Guide<\/title>\n<meta name=\"description\" content=\"Learn how to create a custom Magento 2 module from scratch with this comprehensive guide. From setting up the module directory and routes to implementing CRUD operations, form creation, validation, and data manipulation, this tutorial series covers everything you need for effective Magento 2 development.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create a Module in Magento 2 Step By Step Guide\" \/>\n<meta property=\"og:description\" content=\"Learn how to create a custom Magento 2 module from scratch with this comprehensive guide. From setting up the module directory and routes to implementing CRUD operations, form creation, validation, and data manipulation, this tutorial series covers everything you need for effective Magento 2 development.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/create-module-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=\"2024-08-01T10:52:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-19T13:21:31+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=\"Sagar Bathla\" \/>\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=\"Sagar Bathla\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/\"},\"author\":{\"name\":\"Sagar Bathla\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/6fcd235eb54dfa1a0fbfc662b8618463\"},\"headline\":\"How to Create a Module in Magento 2\",\"datePublished\":\"2024-08-01T10:52:24+00:00\",\"dateModified\":\"2025-05-19T13:21:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/\"},\"wordCount\":296,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/\",\"url\":\"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/\",\"name\":\"How to Create a Module in Magento 2 Step By Step Guide\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2024-08-01T10:52:24+00:00\",\"dateModified\":\"2025-05-19T13:21:31+00:00\",\"description\":\"Learn how to create a custom Magento 2 module from scratch with this comprehensive guide. From setting up the module directory and routes to implementing CRUD operations, form creation, validation, and data manipulation, this tutorial series covers everything you need for effective Magento 2 development.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create a Module 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\/6fcd235eb54dfa1a0fbfc662b8618463\",\"name\":\"Sagar Bathla\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/06e15f8abbf8155cc1124049027a7849db68d785d26bd10e4932883b83def757?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\/06e15f8abbf8155cc1124049027a7849db68d785d26bd10e4932883b83def757?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Sagar Bathla\"},\"description\":\"Sagar Bathla, a Magento Certified Developer, is an expert in Magento 2 development and eCommerce platforms. He specializes in creating cutting-edge Headless PWA solutions, ensuring scalability and exceptional user experiences. Sagar's focus on innovative technology results in transformative digital growth.\",\"url\":\"https:\/\/webkul.com\/blog\/author\/sagar-bathla901\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Create a Module in Magento 2 Step By Step Guide","description":"Learn how to create a custom Magento 2 module from scratch with this comprehensive guide. From setting up the module directory and routes to implementing CRUD operations, form creation, validation, and data manipulation, this tutorial series covers everything you need for effective Magento 2 development.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"How to Create a Module in Magento 2 Step By Step Guide","og_description":"Learn how to create a custom Magento 2 module from scratch with this comprehensive guide. From setting up the module directory and routes to implementing CRUD operations, form creation, validation, and data manipulation, this tutorial series covers everything you need for effective Magento 2 development.","og_url":"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2024-08-01T10:52:24+00:00","article_modified_time":"2025-05-19T13:21:31+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":"Sagar Bathla","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Sagar Bathla","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/"},"author":{"name":"Sagar Bathla","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/6fcd235eb54dfa1a0fbfc662b8618463"},"headline":"How to Create a Module in Magento 2","datePublished":"2024-08-01T10:52:24+00:00","dateModified":"2025-05-19T13:21:31+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/"},"wordCount":296,"commentCount":2,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/create-module-in-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/","url":"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/","name":"How to Create a Module in Magento 2 Step By Step Guide","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2024-08-01T10:52:24+00:00","dateModified":"2025-05-19T13:21:31+00:00","description":"Learn how to create a custom Magento 2 module from scratch with this comprehensive guide. From setting up the module directory and routes to implementing CRUD operations, form creation, validation, and data manipulation, this tutorial series covers everything you need for effective Magento 2 development.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/create-module-in-magento-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/create-module-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create a Module 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\/6fcd235eb54dfa1a0fbfc662b8618463","name":"Sagar Bathla","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/06e15f8abbf8155cc1124049027a7849db68d785d26bd10e4932883b83def757?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\/06e15f8abbf8155cc1124049027a7849db68d785d26bd10e4932883b83def757?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Sagar Bathla"},"description":"Sagar Bathla, a Magento Certified Developer, is an expert in Magento 2 development and eCommerce platforms. He specializes in creating cutting-edge Headless PWA solutions, ensuring scalability and exceptional user experiences. Sagar's focus on innovative technology results in transformative digital growth.","url":"https:\/\/webkul.com\/blog\/author\/sagar-bathla901\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/455496","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\/204"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=455496"}],"version-history":[{"count":14,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/455496\/revisions"}],"predecessor-version":[{"id":492606,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/455496\/revisions\/492606"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=455496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=455496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=455496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}