1

I have create database table and want to create model,resource,Collection class and know that how to create.

Have follow the blog https://www.softprodigy.com/store/article/create-model-and-collection-for-custom-table-in-magento2/

Now, my question if want use created model for API then

  • What classes and interface need to add my Model, Resource,Collection Class?
  • What API classes are need to write?
  • Should i create Factory class of those class?

In single word, how to write an standard Model class to Magento 2

Can any one give a brief and describe answer

2

There is very useful tool from Alan Storm named Pestle allowing you to generate all Magento 2 CRUD classes but also repository interface as well as implementation for your entity using:

pestle.phar generate_crud_model Pulsestorm_ToDoCrud TodoItem

Where Pulsestorm_ToDoCrud is name of your module, and TodoItem your new entity. I suggest you give this a try with version control in place allowing you to inspect each and every class.

Here is link to Pestle tool:

https://github.com/astorm/pestle

and here is link to article from Alan Storm explaining CRUD classes in M2 as well as usage of Pestle tool.

https://alanstorm.com/magento_2_crud_models_for_database_access/

  • Thanks @Marko for this answer.But how i can use my model for API Also – Amit Bera Jan 25 '18 at 11:11
1

It got a reference answer from @kristof-at-fooman.

And he ask me to follow @Vinai Kopp blog.

How to implement service contract for a custom module in Magento 2?

On question Vinai have given a solid answer https://magento.stackexchange.com/a/160617/4564

So,we have to implement server contact for our module. If API, does not need then you don't need to create API point means webapi points.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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