【问题标题】:MVC design and form submission: URL showed to usersMVC 设计和表单提交:向用户显示的 URL
【发布时间】:2013-09-28 00:15:28
【问题描述】:

我对一些 MVC 设计和表单提交有疑问。我想保存资源时遇到了一些问题。

例如,我有一个控制器名称 vehicle 和给定的方法:

vehicle
  |-- list
      `-- GET  - Display the list of vehicle.
  |-- add
      |-- GET  - Display the form for adding a vehicle.
      `-- POST - Save the added vehicle.

我的问题是用户保存车辆后,我想返回显示通知的车辆列表。 view_model.add_notification 是一种在视图上显示通知的方法。

a) 当我在查询字符串中看到 success 时,我将用户重定向到 vehicle/list?success=1 并调用 view_model.add_notification
问题:URL 将包含 success=1 .

b) 在POST 请求中vehicle/add 保存车辆后显示列表并调用view_model.add_notification
问题:URL 将是vehicle/add

c) 我把控制器改成了这个

vehicle
  |-- list
      `-- GET  - Display the list of vehicle.
      `-- POST - Save the added vehicle.
  |-- add
      |-- GET  - Display the form for adding a vehicle.

所以我可以调用view_model.add_notification('success'),然后显示列表,URL 就可以了。
问题:我觉得将保存代码放在@987654334 中的设计不正确@方法。

请问,您能否为我提供一些关于如何设计它的最佳方式的意见?总结一下我写的命题:
a) 错误的网址
b) 错误的网址
c) 糟糕的设计

【问题讨论】:

    标签: forms post-redirect-get user-feedback


    【解决方案1】:

    只需设置一个会话变量,如

    $_SESSION['success'] = true;
    

    并将用户重定向到列表页面。然后就可以了

    if( isset($_SESSION['success']) ) {
    
        // Do what you want to do when success is set
    
        unset($_SESSION['success']);
    }
    

    【讨论】:

      猜你喜欢
      • 2019-11-14
      • 1970-01-01
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多