久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

MVC 設(shè)計 - CodeIgniter MVC Web 應(yīng)用程序項目中可以/應(yīng)

MVC Design - How many controllers can/should/must I have in a CodeIgniter MVC web app project?(MVC 設(shè)計 - CodeIgniter MVC Web 應(yīng)用程序項目中可以/應(yīng)該/必須有多少個控制器?)
本文介紹了MVC 設(shè)計 - CodeIgniter MVC Web 應(yīng)用程序項目中可以/應(yīng)該/必須有多少個控制器?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 CodeIgniter MVC 框架在 PHP 中構(gòu)建一個相對簡單的 Web 應(yīng)用程序.我以前開發(fā)過 PHP 應(yīng)用程序,但從未以嚴格的方式開發(fā)過.我已經(jīng)習慣了 MVC 框架,但是有兩個問題一直讓我回到繪圖板,它拖慢了開發(fā)速度.

I'm building a relatively simple web application in PHP using the CodeIgniter MVC framework. I've developed PHP applications before but never in a disciplined manner. I'm getting used to the MVC framework, however two questions keep bringing me back to the drawing board and it's slowing down development.

  1. 是否有關(guān)于 Web 應(yīng)用程序可以擁有多少個控制器的最佳實踐?我的應(yīng)用程序有一個(相當大的)控制器,其中包括業(yè)務(wù)邏輯、表單提交邏輯等.雖然這有效,但我正在爭論是否有單獨的控制器,例如一個用于表單處理和提交,另一個用于用戶管理(會話、登錄、注冊)等.再說一次,我也不想為此過度設(shè)計.我被掛斷的部分是: 控制器有一個默認"索引函數(shù),可以在父 URL 上加載.所有的業(yè)務(wù)邏輯都從這里開始(例如,表單提交、處理數(shù)據(jù)等).隨著開發(fā)的繼續(xù),我默認只在同一個控制器中創(chuàng)建新功能.它有效,但我的部分目標是同時學習最佳實踐,有些東西告訴我我可能會以錯誤的方式進行.

  1. Is there a best practice on how many controllers a web app can have? I have one (fairly large) controller for my app that includes business logic, form submission logic, etc. While this works, I'm debating whether it would make sense to have separate controllers, e.g. one for form handling and submission, another for user management (session, login, sign up), etc. Then again, I don't want to overengineer the heck out of this either. The part where I am getting hung up is: the controller has a "default" index function that gets loaded at the parent URL. All the business logic starts off from here (e.g., form submission, doing something with the data, etc.). I've defaulted to just creating new functions in the same controller as development continued. It works, but part of my goal is to also learn the best practice and something tells me I may be going about this the wrong way.

模型應(yīng)該用于數(shù)據(jù)庫讀/寫功能還是我可以在其中放置幫助"功能,例如generate_random_number、validate_login_credentials、login_session、logout_session 等

Should models only be used for database read/write functions or can I put "helper" functions in there as well, e.g. generate_random_number, validate_login_credentials, login_session, logout_session, etc.

推薦答案

(這是我的主觀意見 - 它對我很好)

(This is my subjective opinion - it has treated me well)

模型應(yīng)該是整個應(yīng)用程序的骨干.模型應(yīng)該處理所有業(yè)務(wù)邏輯和數(shù)據(jù)庫管理.同時,控制器應(yīng)該盡可能的細化,只真正提供模型和視圖之間的接口.

Models should be the meat and bone of your entire applications. The models should handle all business logic and database management. Meanwhile, the controllers should be as thin as possible, only really providing an interface between the model and view.

例如,在登錄屏幕中,控制器應(yīng)該為用戶提供登錄視圖.當用戶輸入他的信息時,控制器應(yīng)該處理輸入驗證并將輸入轉(zhuǎn)發(fā)給模型,模型應(yīng)該以成功"或失敗"作為響應(yīng).因此,控制器應(yīng)該將用戶重定向到儀表板,或者將用戶發(fā)送回帶有錯誤消息的登錄屏幕 - 分別.

For instance, in a login screen, the controller should provide the user with the login view. When the user inputs his information, the controller should handle input validation and forward the input to the model, which should respond with "success" or "failure". Consequently the controller should redirect the user to the dashboard, or send him back to the login screen with an error message - respectively.

總結(jié):模型應(yīng)該是胖的,控制器應(yīng)該是瘦的.

這篇關(guān)于MVC 設(shè)計 - CodeIgniter MVC Web 應(yīng)用程序項目中可以/應(yīng)該/必須有多少個控制器?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應(yīng)用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發(fā)技術(shù)
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網(wǎng)站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務(wù)層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 日本久久久一区二区三区 | 免费在线日韩 | 亚洲视频免费在线观看 | 久久i| 国产成人小视频 | 色中文在线 | 古装三级在线播放 | 久久久久亚洲精品国产 | 一呦二呦三呦国产精品 | 欧美午夜一区 | 国产精品一区二区欧美黑人喷潮水 | 日本超碰| 国产99精品 | 精品一区二区三区四区在线 | 亚洲精品一区二区三区 | 国产成人久久精品一区二区三区 | www.一级片 | 亚洲 日本 欧美 中文幕 | 国产精品一区二区久久 | 欧美精品一区三区 | 91人人爽 | 91福利影院| 影音先锋中文字幕在线观看 | 一区二区三区在线 | 草草视频在线播放 | 福利视频网| 久国产视频 | 久久午夜剧场 | 国内精品视频在线观看 | 亚洲一区二区三区在线观看免费 | 亚洲一区二区在线播放 | 国产成人99av超碰超爽 | 国产一级在线 | 最新免费av网站 | 亚洲免费视频在线观看 | 国产欧美精品一区 | 黄色毛片在线看 | 久久精品国产精品青草 | 欧美一区免费在线观看 | 天天干夜夜操 | 久久国产精品一区二区三区 |