問題描述
我正在尋找指導我了解 Controll 功能和編寫自己的控制器 + 模型的最佳實踐的教程/書籍
I am looking for a tutorial / book that guides me to understand the Controll functions and the best practices to write my own controller + Model
提前致謝.
推薦答案
我確信已經發布了很多鏈接來幫助您入門,但是創建 MVC 的一些重要因素是:
Im sure theres plenty of links been posted to get you started but some important factors in creating an MVC is:
- 靜態注冊表類(存儲對象并在全局范圍內獲取)
- 路由器(從 URI 中確定控制器/方法和參數的類)
- 基礎控制器(只是一個小的抽象類,然后用戶控制器可以擴展)
- SPL 自動加載(這將允許用戶擴展類,例如
Model_Database
) - 結構(根據名稱創建目錄,即
Library_session
會加載/library/session.class.php
) - 模型抽象(所有類型的存儲、數據庫、磁盤等的帳戶)
- 錯誤跟蹤(始終確保您的日志記錄和捕獲錯誤)
它們只是您在創建系統時應該考慮的一些提示和想法.
They are just a few tips and ideas you should be thinking about when you create your system.
您還應該做的是使用其他框架并構建一些示例項目,了解應該如何使用 MVC 框架,所以當您構建一個時,您知道用戶應該期望什么,然后真正研究框架的核心結構.
What you should also do is user other frameworks and build some sample projects, learn how an MVC Framework should be sued, so when your building one you know what the user should expect, then just really study the core structure of the framework.
在 PHP 中考慮以下通常是 MVC 的工作方式
Take into consideration in PHP the following are usually how MVC Works
- 控制器(根據 URI 執行)
- 模型(從控制器訪問,應該是數據的 I/O)
- 查看(基本上是模板)
但您可以使用 MVCL
,即 (M odel/V iew/C ontroller/L 語言)
but you can work with a MVCL
which is (M odel/V iew/C ontroller/L language)
語言不是原始文檔中的特定語言,但在模式結構方面被采用了幾次,下面的文件結構示例將引導您了解 +L的主要用途強>
Language is not a specific in the original documentation but its been adopted a few times in regards to the pattern structure, An example of the file structure below will guide you into whats the main purpose of the +L
M: catalogmodelcatalogproduct.php
V: catalogview emplateproductproduct.tpl
C: catalogcontrollerproductproduct.php
L: cataloglanguageenglishproductproduct.php
公司/項目使用這種方法的一個例子是:OpenCart,我強烈建議你看看架構!
An example of what company / project uses this method is: OpenCart, AND I HIGHY RECOMMEND YOU LOOKING AT THE ARCHITECTURE!
這篇關于MVC - 控制器類教程的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!