实现面向对象的PHP和AJAX,MVC? [英] Implementing OOP PHP with AJAX, MVC?

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

问题描述

我是新来的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.

presumably时AJAX时,充当控制器与模型直接交互以检索任何功能需要的?我添加的文件名都只是给你什么,我'想'的想法应该被包括在内。例如index.php文件将是一个HTML / CSS模板包括在相关位置模块(无论是什么) - news.php,navigation.php等为da​​tabase.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?

我可能portayed我的困惑以及在这里 - 我应该走在视图,控制器和模型......是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.

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

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