0

Could someone possibly explain the structure and what files are for in a CRUD module? I have created by module by following a guide online, and its working great and printing out my database fields on the page, but i'm a bit confused as to what some of the files do?

Here are my files so far and what i've gathered they do

Vendor/Module/Api/Data/PostInterface.php

I have no idea what the interface file does, some guides have it and some do not and I can't seem to make sense of it.

Vendor/Module/Block/PostList.php

The block file that connects directly to my template files for rendering data in the templates and layout.

Vendor/Module/Controller/Index/Index.php

The index file that renders the template for the requested page?

Vendor/Module/etc/frontend/routes.xml

The xml file that specifies the routes for the url.

Vendor/Module/etc/module.xml

The module declaration xml file.

Vendor/Module/Model/ResourceModel/PostModel/Collection.php

I think this file is the one that connects to the database?

Vendor/Module/Model/ResourceModel/PostModel.php

I have no idea what the resource model does.

Vendor/Module/Model/PostModel.php

Our actual model file.

Vendor/Module/Setup/InstallSchema.php

The file that installs the database tables.

Vendor/Module/view/frontend/layout/postmodel_index_index.xml

The index layout file.

Vendor/Module/view/frontend/templates/list.phtml

The template file that we connect to our block to load data.

I'm fairly new to magento 2, and I haven't used magento 1 before. I think I have a basic understanding of what all the files do, but if someone could briefly explain exactly what each of the files are for, i'd be very grateful!

Thanks in advance

1
  • Can you share the link that you used to create this CRUD module. Also, have you heard about the repository pattern in magento? Try searching for service contracts in magento. Commented Mar 3, 2020 at 12:51

1 Answer 1

0

you can check this guide it explain all classes used for CRUD + steps to create and manage custom table in database

source mageplaza

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.