【问题标题】:How to get html input values like Laravel using Interfaces如何使用接口获取像 Laravel 这样的 html 输入值
【发布时间】:2023-01-13 15:55:28
【问题描述】:

我想使用像请求这样的接口方法获取 html 数据。如果有人知道请解释我。

我想得到这样的输出!请帮助编写示例请求 php 接口。

public function create(Request $request) {
   echo $request->inputname;
   echo $request->anotherinputname;
}

【问题讨论】:

  • 您不会从界面“得到”任何东西。接口只是一个类在实现该接口时必须遵循的契约。您是在问如何构建请求类吗?这个问题太宽泛了。做appropriate amount of research,先自己做一些尝试。如果您在此过程中遇到特定问题,请发布minimal, reproducible example 并解释您遇到的问题。
  • “接口方法”是什么意思?这与“请求”有什么关系?

标签: php class input interface


【解决方案1】:

它不像你想的那样工作。 Laravel 使用依赖注入。 您可以定义一个 Request 类,并在其构造函数中将 POST 数据映射到属性。 是这样的:

class Request {
    public $get;
    public $post;

    public function __construct() {
        $this->get = $_GET;
        $this->post = $_POST;
    }
}

然后您可以通过这种方式访问​​ POST 数据:

$request->post['anotherinputname'];

【讨论】:

    猜你喜欢
    • 2011-06-05
    • 1970-01-01
    • 2023-03-19
    • 2014-04-12
    • 2015-12-13
    • 1970-01-01
    • 2012-12-25
    • 2018-03-01
    • 1970-01-01
    相关资源
    最近更新 更多