Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
500 views
in Technique[技术] by (71.8m points)

php - MVC:这是初始化和调用MVC层的正确顺序吗(MVC : Is this the correct sequence to initialize & invoke MVC layers)

I am trying to learn php MVC based webpage development.At first i literally thougt that it's just decoupling the project into 3 classes Model, View, Controller.But with help SO previous post comments, i realized that these are Not class but instead they are layers

(我正在尝试学习基于php MVC的网页开发。起初我只是想将项目分解为模型,视图,控制器3类,但是在之前的评论的帮助下,我意识到这些不是类,而是它们层数)

// don't be confused my class/OOP style, it is just for conceptual purpose
Model.php Layer related code   
View.php Layer  related code   
Controller.php Layer related code   

User: index.php
//initiating model layer related things
$m = new Model;
// initiating Controller layer related things
$v = new Controller($m);
// initiating view layer related things
$c = new View($m, $c);

However, there are many MVC example over internet which are confusing and conflicting sometime.For example some suggest: controller have the access of both model & view, where other suggest view have the access of both.So please anyone check my code sequence to ensure that it does follow the MVC pattern correctly.

(但是,Internet上有很多MVC示例,它们有时会造成混淆和冲突。例如,一些建议:控制器可以同时访问模型和视图,而其他建议视图可以同时访问两者,因此请任何人检查我的代码序列以确保它确实遵循MVC模式。)

  ask by user5005768Himadree translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In my opinion coming from PHP and Javascript Model - Where you data lives, and is manipulated for extraction.

(我认为来自PHP和Javascript模型-您将数据存放在何处,并对其进行操作以进行提取。)

Controller - Pulls in data from model(s) and anything else and is moulded into something for the user, could be a view or and endpoint.

(控制器-从模型和其他任何东西中提取数据,并为用户铸造成某种形式,可以是视图或端点。)

View - UI which gets data from Controller and all passes data to controllers ie forms.

(视图-从控制器获取数据并将所有数据传递到控制器(即表单)的UI。)

View never interacts with Model.

(视图从不与模型交互。)

A concept i like is Top heavy Models, light Controllers.

(我喜欢的一个概念是顶级重型模型,轻型控制器。)

I personally don't think their is a hard rule, just guides

(我个人认为这不是硬性规定,只是指导)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...