Reputation: 1216
I am currently trying to understand how the MVC framework does work in PHP. Therefore, I have created this basic sketch of how I think
that MVC is implemented in PHP:
[I know that some steps are missing, e.g. how the Router
parses the route
in order to know what View
and Controller
to load, but these steps are rather technical based and are not important in order to understand the general flow of MVC in PHP.]
I draw my understanding of MVC in PHP from this article series. However, I think that this structure will differ from most of the structures people think off, when they talk about MVC in PHP, because of this article (The article basically states that not only the Controller
but also the View
does communicate with the Model
).
What I'd like to ask you now are several questions:
right
way of implementing MVC in PHP?AjaxViews
do only return e.g. json objects
and the AjaxControllers
do always expect authentication codes to prove that these ajax calls are legtitim?I know that there have already been asked dozens of questions about MVC in PHP and I've been reading quiet a lot of articles until now, but I think that only reading does not enable me to understand MVC completely.
Furthermore, after reading the articles linked above, I'm not longer sure whether other articles about MVC, I find on the web, does explain MVC the same way as the articles above. Because if they don't, I'm trying to understand one framework while reading about two or multiple different approaches.
Thank you very much in advance for taking the time to answer my question!
According to the answer below I've changed my MVC sketch. Just in case someone finds this link and wants to know more.
Upvotes: 4
Views: 827
Reputation: 39
It is for parallel development and code reuse ability. There is a separation of concern how your system works and how users work. This provides a solution of the problem. There is boundry now, MVC.
Upvotes: 0
Reputation: 174947
Let me first answer your questions, then place my take on it.
Accept:
HTTP header (and send something like Accept: application/json
in your AJAX requests). Your view then returns a JSON template instead of an HTML template.Your model isn't just the gateway to your database, it's where all the logic happens. All the computation. See this yet another excellent answer that explains How should a model be structured in MVC?.
The idea of MVC is to simply separate your application into three layers: Input (controller), Logic (model) and Output (view). This is to extend on the usual way PHP works (here's a request, give me a response, all in the same page).
For that reason, implementation details may vary, the concept is what matters. "Web MVC" is merely the result of good OOP practices and some naming convention someone made up a few decades ago.
Upvotes: 4