【问题标题】:Where (in which class) to collect the information that the user is sending (POST and GET)?在哪里(在哪个类中)收集用户发送的信息(POST 和 GET)?
【发布时间】:2016-01-02 14:20:21
【问题描述】:

我在那儿:

我正在使用 PHP 设计一个通用 Web 系统,用户发送信息,然后系统收集它,然后我创建模型,应用逻辑等,最后创建 html 结果。

我在 SRP 下工作,因此我为每项工作(模型、逻辑、网络等)创建不同的类,但我不知道在哪里收集用户发送的信息,即我应该把 $_GET 和 $_POST 放在哪个类?

a) 在所谓的“控制器”类中?

b) 在外观类中?

c) 我不能申请模型(域)类,因为虽然收集的大部分信息都是关于模型的,但用户发送的其他信息超出了模型的范围(例如“动作”, “按钮”等)。

d) 将其直接发送到 ViewModel?。

e) 其他。

例子:

<?php

 include "model/Customer.php";
 include "....."; // other includes.

 $customer=new Customer();
 // where this part: ???
 $customer->idCustomer=$_GET['idCustomer'];
 $customer->name=$_GET['name'];
 // end ???

 $vm=new CustomerVM();
 $vm->customer=$customer;
 // logic here
 $logic=new CustomerLogic();

 // view here
 $view=new CustomerView($vm);
 $view->insertForm();

?>

【问题讨论】:

标签: php http-post http-get


【解决方案1】:

我猜你使用 MVC 模式。

控制器合并和委派。所以控制器从 POST/GET/PUT 等获取输入是对的。

文档:http://c2.com/cgi/wiki?ModelViewController

【讨论】:

    猜你喜欢
    • 2015-07-13
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    相关资源
    最近更新 更多