In the mvc architecture can my controller connect with different models?

0

for example: If I want to register a vehicle (attributes: model, license plate, year) and it has a brand (attributes: name, country)

My class driverVehicle can only connect with my class modelVehicle and modelVehicle would connect with modelBrand

or my class driverVehicle would connect with my class modelBrand and my model classVehicle

I am carrying out a project and I really have many doubts about how the mvc architectural pattern works in these situations

    
asked by banana_potato_nah 18.09.2017 в 03:48
source

1 answer

0

There could be different possibilities depending on the specific case and the language and platform used. But, in general, when the models (types, classes, ...) defined in an application do not fit the needs of the information to be displayed in a view, what is usually done is to define a specific model to work with the view , which is called "view model".

Note that the MVC pattern is a specific pattern for working on the application's presentation layer. The models used in the presentation layer do not necessarily have to match exactly the models used in the business layer, in fact they usually do not coincide except in very simple applications.

In your case you could create an InfoVehicle model and the controller would be responsible for obtaining the information of the different models of the business layer (modelVehicle, modelBrand, ....) and assemble with it the model InfoVehicle that would be the that will come into view.

It would also be responsible for receiving the InfoVehicle model from the view and passing the information received in the models defined in this layer to the business layer of the application (modelVehicle, modelMarca, ...).

    
answered by 18.09.2017 / 12:44
source