問題描述
我是 MVC 的新手,我的第一個框架是 Laravel(現在是 3 個).我已經開始專門在路由中編碼,然后我轉向了控制器.但是,我正在控制器中執行所有數據庫操作.我不明白如何使用模型.
示例要么演示控制器中或路由中的所有內容,但它們從未拆分模型、控制器和視圖.
誰能告訴我如何使用該模型?簡而言之,我不明白如何將它們相互鏈接,例如將表單輸入發送到它們的模型,或將處理后的數據發送回控制器.
具有完整 MVC 設置的 Laravel(如果可能,v3)的 github 存儲庫也可以很好地分析,如果有人有一個給我看?
謝謝.
我聽過的關于框架主題的最佳陳述歸功于鮑勃叔叔:
<塊引用>好的架構可以推遲重大決策!
特別是:
- 好的架構會延遲選擇框架!
另一個值得思考的偉大作品:
<塊引用>MVC 不是架構!這是一種交付設計模式.
觀看他的視頻 - 可悲的是,它是為數不多的沒有花 1000 字來說明 10 中可以說的內容的視頻之一,我不能高度推薦它 - 它會幫助您理解很多要點在您的問題中提出:
Robert C Martin(鮑勃叔叔) - 清潔建筑和設計 - 視頻>
當然,他的《Clean Code》一書也值得推薦!
I'm new at MVC and my first framework is Laravel (3 for now). I've started coding exclusively in the routes, and I moved to the controller. I'm however doing all of my database operations in the controller. I do not understand how to use the model.
Examples either demonstrate everything in the controller or in the route, but they never split the model, controller and view.
Could anyone kindly explain me how to use the model? In short I don't understand how to link one to each other, like sending form input to them model, or processed data back to the controller.
A github repo of a Laravel (v3 if possible) with a full MVC setup would be nice to analyze too, if anyone has one up for me to look at?
Thanks.
The best statement on the subject of Frameworks I've heard is due to Uncle Bob:
A good Architecture allows major decisions to be deferred!
Specifically:
- A good Architecture delays choosing a Framework!
Another great piece to think about:
MVC is not an Architecture! It is a Delivery Design Pattern.
Watch his video - it is one of the sadly few ones out there that don't spend 1000 words on what can be said in 10 and I can't highly enough recommend it - and it will help you to understand many points raised in your question:
Robert C Martin(Uncle Bob) -Clean Architecture and Design - Video
Of course, his book on Clean Code is also highly recommended!
這篇關于Laravel 3:尋找如何使用模型的解釋的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!