What is the purpose of the Model folder of the Inphinit framework?

Asked

Viewed 373 times

9

In the Inphinit micro-framework there is the Model folder inside the folder application, and that’s where the classes are, but I’m very confused about those classes.

See a class inside the Model folder:

<?php
namespace Model;

class User extends \Inphinit\Experimental\Model
{
}

Doubts

  1. I would like to know what is the purpose of the Model folder?
  2. What are the classes in the Model folder and how important they are these classes relate to the operation of my web application?

If you can explain me with practical examples it will be easier for me to understand.

  • 2

    @Guilhermenascimento will be able to better explain :P, but if it follows the standard [tag:mvc] (Model, View, Controller), Model usually houses the database queries.

2 answers

8

I would like to know what is the purpose of the Model folder?

Normally in web applications we use a form of project organization called MVC. (MOdel-View-Controller)

  • Model Classes related to database and business rules

  • View Templates with HTML/Template language to view your application content.

  • Controller Classes that control the application. It’s like a glue between models and views. It is usually in the controllers that the application checks whether it is a GET,POST, etc and makes the decisions about which View to show, how to process the data, etc.

What are the classes in the Model folder for

In this organization model the classes that correspond to the business rules and connection to the database usually stay in the folder Model.

It is a form of organization and you can choose to follow it or not.

and what importance these classes have in relation to the functioning of my web application?

The importance of the models is to clarify and separate the business and database rules from the rest of the application.

Currently MVC is widely used in frameworks, although I never see a structure exactly the same or standardized. This serves more as a guide line to maintain the organization, but you are always free to change and use as your need.

  • Just to complete a little more the controller explanation, as I understand it: The controller is responsible for responding to requests to the server. Know if it’s a GET, a POST or something else and act to respond to requests by accessing models and returning views.

  • 1

    @cav_dan, edited the question and added a slightly better explanation of the controller. Thanks for the tip :)

2


jHertel has already given a brief introduction to what MVC is, some questions that may help you with this specifically:

From my summary point of view, MVC does not have a specific pattern, in fact in many ways you can make use of this and achieve the same result, can be strict or not, the inphinit is not strict (strict), in fact it is well "free", except for the Controllers which are almost always mandatory (although bear Closures).

So the MVC is a way of organizing and not a technology, from my point of view, the most common MVC represented is this:

mvc

inphinit follows many things similar to other known frameworks, having the folder and namespace for Controller and Model (View no namespace), this class you posted was one of the experimental examples you were performing:

<?php
namespace Model;

class User extends \Inphinit\Experimental\Model
{
}

At the time I removed the class \Inphinit\Experimental\Model, not because it is wrong, but because it does not yet achieve what I hope, from my point of view Models has nothing to do with database, they only use the data contained in them, the goal of the Model is to define the "business rules", thus making use of any kind of information, having the ability to get them, update and delete, but all this having rules.

However, I believe that a Model, wherever it is, should never manipulate things directly, such as sending data to the ouput, or sending a response, it should only send the answer (if any) to the controller and the controller should take care of the rest (of course I appreciate this with the experience I had with totally different tools, as MVC said is not always the same in two different places or frameworks).

In most of the frameworks I notice the Model is used merely as a connecting instrument with the bank and some rules end up falling within the Controller.

When I idealized inphinit he had 5 goals:

  1. Support PHP 5.3
  2. Spend as little memory as possible
  3. Be as fast as possible without numerous cycles inside the core.
  4. Be as simple as possible for learning
  5. Support third party libraries (3rdparty) that is installed via Composer

With this ultimate goal we come to namespace Model; and the folder system/application/Model/, the framework has nothing like Migration, connection and sqlbuilder, but this does not mean that you can not install things from third parties, there are frameworks that even used with it as:

That is the focus of the folder and namespace Model is the same as most frameworks, however it can be used with the ORM you desire or as you wish

As soon as possible Add a step-by-step from one or more frameworks to work with the namespace Model.

Browser other questions tagged

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