Doubt regarding the MVC

Asked

Viewed 52 times

1

I’m doing my first project using MVC in PHP, and I came across this question:

In relation to ajax and requisições assíncronas, when I request a page, that page that processes the ajax request would be the controller

(Ex: view-ajax ~> controller-php ~> model-php)

Or I would have to make a page that is called by ajax and that page calls the controller?

(Ex: view-ajax ~> auxiliary page ~> controller-php ~> model-php)

Thank you!

  • 1

    Dear Leandro I don’t see this way, I see ajax as an action and only, You don’t even need to have a controller.php for a specific model.php and auxiliary page, You can use a lot of MVC or check to be MVC, even the idea of implementing many people’s MVC may simply be wrong, but people do it anyway, MVC is not technology and does not necessarily have a correct or exact cake recipe, not everything needs MVC, both examples may be right or wrong, can’t be sure the way you described, but to summarize I think you should look at other Fws...

  • 1

    ...Before implementing your own idea, there are many people who do this, say that OOP is better, procedural is bad, that MVC depends on OOP, but it’s a lot of fallacies, even have a question about HTTP and MVC: https://answall.com/q/60830/3635 ... you can be sure that here in your question will come out several answers that seem correct, but can be a series of mistakes.

  • 1

    There are some similar questions, but I found it interesting to answer yours to illustrate what role the controller plays in the mvc pattern. But out of curiosity, you’re using some php framework?

  • I am not using any framework as I have no practice at all. I usually program in Java using Hibernate. And in this case, the purpose is to pass my TCC project done in procedural to OOP, only for PHP study in the project standards part.

1 answer

3


Friend, I will try to describe in a simple and objective way. Your first example is more correct in my opinion.

In the basic standard of MVC controller has the function of being the "dude" responsible for acting upon a request (route) and possibly relating to models or with views to deliver what was requested. He is the controller of the actions. Therefore, I see no reason not to use the controller directly.

In my view it is correct yours view make the ajax request to a route and that this calls the controller for information on a model and respond with this data. At least that’s how it works in most frameworks I know.

Browser other questions tagged

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