使用 AJAX、MVC 实现 OOP PHP? [英] Implementing OOP PHP with AJAX, MVC?

查看:18
本文介绍了使用 AJAX、MVC 实现 OOP PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 OOP 范式(和 AJAX/jQuery)的新手,但想创建一个使用 MVC 架构的基本站点,在 PHP 中,具有 AJAX 功能.我绘制了一个简要图表,说明我目前如何理解"架构.

I'm new to the OOP paradigm (and AJAX/jQuery), but would like to create a basic site employing MVC architecture, in PHP, with AJAX functionality. I drew up a brief diagram of how I currently 'understand' the architecture.

大概当使用 AJAX 时,它充当控制器直接与模型交互以检索所需的任何功能?我添加的文件名只是为了让您了解我认为"应该包含的内容.例如index.php 将是一个 html/css 模板,其中包含相关位置中的模块(无论它们是什么) - news.php、navigation.php 等.database.php/pager.php 可能包含类和扩展类我创建分页,或连接/查询数据库我正在努力查看控制器组件可能是什么 - 它肯定会最终成为第二个后端视图" - 从要发送到的模型中调用类视图?

Presumably when AJAX is used, that acts as the controller to interact with the model directly to retrieve whatever functionality is needed? The filenames I added are just to give you an idea of what I 'think' should be included. e.g. index.php would be a html/css template with includes to modules in the relevant places (whatever they may be) - news.php, navigation.php, etc. database.php/pager.php might house the classes and extended classes that I create for pagination, or connecting/querying the database I'm struggling to see what the controller component could be - it'd surely end up being a 'second back-end view' - calling the classes from the model to be sent to the view?

我可能已经在这里很好地表达了我的困惑 - 视图、控制器和模型中应该包含什么... AJAX 功能在技术上是另一个控制器吗?任何类似于我上面的图表都会非常有帮助.

I've probably portayed my confusion well here - what should go in the view, controller and model... is AJAX functionality technically another controller? Any diagram similar to my one above would be extremely helpful.

推荐答案

好的,所以 AJAX 是一种传输方法,而不是像模型或控制器这样的应用程序.

OK so AJAX is a transport method and not a piece of application like a model or controller.

您的客户将通过 AJAX 与一个或多个控制器进行通信.

Your client will communicate through AJAX with one or more Controllers.

这些控制器使用或调用模型来处理不同类型的任务.

These Controllers use or invoke Models to handle different kind of tasks.

然后控制器或模型使用传输友好格式(JSON、YAML、XML)或视图(一段 HTML)的消息响应请求.

Then either the controller or the model responds to the request either with a message in a transport-friendly format (JSON, YAML, XML) or with a View (piece of HTML).

控制器处理请求,这意味着它接收初始客户端输入.根据具体情况,在您的应用程序中使用该输入之前,必须对其进行格式化、规范化、变异或转换.

The controller handles requests, that means it receives the initial client-input. Depending on the situation this input has to be formatted, normalized, mutated or transformed somehow before being used in your application.

然后控制器使用或调用模型;这意味着它要么处理业务逻辑本身(旧样式)并利用模型访问数据源,要么将应用程序的主要工作流完全交给模型(新样式).

Then a controller uses or invokes a model; this means that it either deals with business logic itself (old style) and makes use of the model to access datasources or it hands the main workflow of your application completely over to the model (new style).

首先,模型抽象了一个持久存储实体(如数据库).在现代应用程序设计中,它还负责应用程序的主要业务逻辑.

A model in first instance abstracts a persistent storage entity (like a database). In contemporary application design it also does the main business logic of your application.

这篇关于使用 AJAX、MVC 实现 OOP PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆