Are models in the MVC structure for database operations only?

Asked

Viewed 150 times

4

I learned that "Whenever you think about data manipulation, think about model. It is responsible for reading and writing data, and also for its validations."

Later another person told me that models is exclusively for data processing more specifically database interface, server connection (or other), update, Insert, delete, select and those things relating to database.

In that case if I have a class called getAllPageContents responsible for:

  • Download a certain web page.
  • Extract all metatags from this page
  • Extract all links and text from this page

And that it returns in an array format. If I want to make this class a model of my MVC I couldn’t? As it is not related to database operations?

In my case this same person recommended me that this logic of the above class should be inside the controller itself or in a separate file but not considered as a model and outside the model folder.

I wonder if this information that the files inside the model folder are unique only for database operations is true, and if it is a Pattern design?

  • For the examples you gave, it is usually made use of such files as components, so you do not bind to the business rule. The model not only limited to BD, you can have a model for generating log in a BD table and at a certain point you choose to create a TXT, but every rule of creation for the log will still be in the model. - superficially explaining

1 answer

1

Models refer to business rules

The Model layer refers to anything related to the application’s business rules, i.e., it is not limited to the database.

If the items you listed are part of the rules that define how your project works, then they belong to the Model layer. There is no need to limit yourself, as this layer can contain validations, read file data and etc.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.