douyujun0152 2017-02-07 00:59
浏览 72


This is a question about theory, so there is no need for code snippets.

I built a router that, as a typical router does, dispatches a controller based on the URL. The workflow is something like this:

  1. Router dispatches controller and instantiates it
  2. Controller renders a view
  3. User interacts with the view
  4. Controller updates model based on user interaction
  5. Model returns the new state of the data to the controller
  6. Controller updates the view based on new data

So basically, the controller is the starting point and the link between the model and view. The model and view never directly interact with each other. The controller is the workhorse and has most of the code.

Now, that is all good and I get it. The confusion comes when I read articles about MVC design patterns and realize what they describe is not what I just described above. It seems like, in the pattern you start at the view. The view talks directly to the model and the controller accepts user interaction to update the model.

So, what I'm doing may involve models, views and controllers, but its not strictly the MVC design pattern. I did read one article where they called what I first described as CAV, controller action view.

My question is, what is it that I'm describing? I don't want to keep referring to it as MVC if its not actually MVC. From what I read true MVC was birthed in the 70's. Things have changed since then. Perhaps what I'm doing is some evolved version of MVC, but not MVC in its strict form. Is there another name for it so I can stop confusing myself, and others, by calling it MVC?

  • 写回答

2条回答 默认 最新

  • duanfan1869 2017-02-07 01:56

    I think its language (technology) dependent. You tagged your question with the php tag, so I suppose you're developing applications using this language. In a classic PHP application, the view can't get updates from the model (in fact, this more related to the PHP language being executed only on the server).

    First, the entire application is launched for each request and is terminated when all the response has been sent. So, the router is called for each request.

    Then, the router execute the controller which have to handle the request (according to routing rules).

    The request being for reading or writing does not modify this behavior.

    If you want to allow the view to ask for data modification approval to your controller, you may need to use some client-side programming language (Javascript). So, you may use a REST API to handle communication between the model and the view.

    To answer your question, I think you can't implements a pure MVC design pattern on a client-server model without using a programming language on the client.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 关于模型训练的一个问题
  • ¥15 装了几千台服务器从来没遇到这种问题,哎看下哪位帮我解决吧
  • ¥15 单片机程序上的困难问题
  • ¥15 请教某软件缓存Ts文件破解合并mp4的方法
  • ¥15 求小游戏炸弹人中关于敌人的C++代码
  • ¥15 拿到这个服务器最高权限有偿
  • ¥50 来个抓app跳转支付宝转链接的
  • ¥15 remotes安装提示没有description文件
  • ¥15 AttributeError: 'NoneType' object has no attribute 'drop_duplicates'报错
  • ¥15 以下代码,运行结果报错