MVC 框架(在本例中为 PHP)
可能的重复:
如何在 PHP 中从头开始实现 MVC?
让我来了解一下直接说:
模型=您的数据库表名称
控制器=用户交互和应用程序逻辑之间的中间人
视图=??
那么视图是动态 PHP 页面还是 HTML 片段?
我希望我能快速了解 MVC,因为我真的很想尽快实现它们
Possible Duplicate:
How to implement MVC from scratch in PHP?
Let me get this straight:
Model = your database table name
Controller = the middle man between user interaction and application logic
View = ??
So is a view a dynamic PHP page or a fragment of HTML?
I'm hoping i can get my head around MVC's quickly because i really want to implement them soon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下MVC的解释摘自codeigniter用户指南。
模型代表您的数据结构。通常,您的模型类将包含帮助您检索、插入和更新数据库中的信息的函数。
视图是呈现给用户的信息。视图通常是一个网页。视图也可以是页面片段,例如页眉或页脚。它还可以是 RSS 页面或任何其他类型的“页面”。
控制器充当模型、视图和处理 HTTP 请求并生成网页所需的任何其他资源之间的中介。
http://codeigniter.com/user_guide/overview/mvc.html
编辑:您可以在每个实体中包含的内容的示例
控制器(此文件是浏览器的目标)
模型
视图
显然,这这是一个极其简化的示例,但希望这能让您大致了解什么应该放在哪里。
The following explanation of MVC is taken from the codeigniter user guide.
The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.
The View is the information that is being presented to a user. A View will normally be a web page. A view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of "page".
The Controller serves as an intermediary between the Model, the View, and any other resources needed to process the HTTP request and generate a web page.
http://codeigniter.com/user_guide/overview/mvc.html
Edit: Example of what you may include in each entity
Controller (this file is targeted by the browser)
Model
View
Obviously, this is an extremely simplified example but hopefully this gives you a rough idea of what should be going where.
视图知道如何显示数据。该视图知道您想要将某些值设置为红色,并将这些值显示为列表,并且您想要使用拖放来重新排列列表。它不知道这些值从哪里来,因此您可以专注于布局和用户交互。
控制器不知道任何特定的布局或行为。控制器只知道如何给出视图值,如何保存列表的顺序等。
The view knows how to display the data. The view knows you want to color some values red, and display these values as a list, and you want to use drag-and-drop to rearrange a list. It doesn't know where these values come from, so you can focus on the layout and user interaction.
The controller doesn't know any of that specific layout or behavior stuff. The controller only knows how to give the view values, how to save the order of the list, etc.
模型是数据和数据库。控制器介于模型和视图之间。这些视图通常是(在 PHP 中)HTML,其中混合了一些 PHP。将视图视为站点的模板。视图负责将模型中的数据呈现到合适的用户界面中。
视图通常是不同 HTML/PHP 页面的系统(一个用于页眉的模板,一个用于页脚的模板,一个用于正文的模板,还有更多用于网站不同方面的模板)。
编辑以下是如何编写菜单视图的基本示例:
Models are the data and the DB. The controller intermediates between model and view. The views are typically (in PHP) HTML with some PHP mixed in. Think of the view as a template for the site. The view is responsible for rendering the data from the model into a suitable user interface.
The view is typically a system of different HTML/PHP pages (a template for the header, one for the footer, one for the body, and more for different aspects of the site).
EDIT here's a basic example of how you might write a view for a menu:
PHP 本身就是一种模板语言,因为它可以与 html 一起使用,尽管还有其他可用的模板解决方案,例如 smarty (对设计者友好)。在您看来,您基本上会这样做
consing fil Foo.phtml
你的视图类可能有 loadView() 函数,
在你的控制器类中
大多数 php MVC 框架都是这样工作的。在 Controller 类中,您可以创建模型对象并使用它。 (我编写的所有代码都是为了解释目的,只是尚未经过测试)
PHP is a template language in itself since it can be used with html , although there other template solution available such as smarty (which are designer friendly) .Bassicaly in your view you would be doing
consing fil Foo.phtml
Your View Class might have function loadView() inside which
In your controller class
Most of the php MVC framework work this way . Inside Controller class you can create model object and use it . (All the code I have writter for explaining purpose only it has been not tested )