問題描述
我剛剛進入 MVC 設計模式.這里的一個簡單示例并沒有明確我對控制器使用的概念.能否請您解釋一下控制器的實際使用,同時保持簡單.
I am just heading into MVC design pattern. A simple example here does not clear my concept about the use of controller. Could you please explain real use of controller while keeping it simple.
型號:
控制器:
查看:
索引:
推薦答案
MVC 模式中控制器的目的是改變模型層的狀態.
Controllers purpose in MVC pattern is to alter the state of model layer.
它是通過控制器接收用戶輸入來完成的(優選 - 抽象為諸如 Request
實例之類的東西),然后根據從用戶輸入中提取的參數,傳遞模型層適當部分的值.
It's done by controller receiving user input (preferable - abstracted as some thing like Request
instance) and then, based on parameters that are extracted from the user input, passes the values to appropriate parts of model layer.
與模型層的通信通常通過各種服務發生.反過來,這些服務負責管理持久性抽象和域/業務對象之間的交互,也稱為應用程序邏輯".
The communication with model layer usually happens via various services. These services in turn are responsible for governing the interaction between persistence abstraction and domain/business objects, or also called "application logic".
控制者不負責什么?
MVC 架構模式中的控制器不負責:
- 初始化部分模型層
- 從模型層檢索數據
- 輸入驗證
- 初始化視圖
- 選擇模板
- 創建響應
- 訪問控制
- ...等
這篇關于MVC模式中使用PHP的控制器的目的是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!