【问题标题】:In Codeigniter REST_Controller $this->post('key'); is always null?在 Codeigniter REST_Controller $this->post('key');总是为空?
【发布时间】:2019-08-16 01:56:58
【问题描述】:

我得到 $this->post('key') 的空结果。我尝试了所有可能的解决方案和建议,但没有一个对我有用。

我尝试过的是,var_dump($_POST) 给出的是 null,但是当我尝试 var_dump($_REQUEST) 时,我收到了请求的内容,包括标题、会话和通过 POSTMAN 发送的数据。另外,尝试了标题内容类型:application-json。仍然,没有什么对我有用。我不得不调查库的核心并取出 post 方法并将 $this->_post_args = $_POST 替换为 $this->_post_args = $_REQUEST 并且它工作正常。但是,这不是正确的方法。

$mobile = $this->post('mobile');

    if(!is_numeric($mobile) || strlen($mobile) != 10){
        $this->response(['status'=>$mobile, 'message' => 'Invalid Mobile Number, 10 digits are required'], REST_Controller::HTTP_BAD_REQUEST);
    }

{ "status": 'mobile number', // 只是为了测试输出 "message": "无效的手机号码,需要 10 位数字" } 但实际情况是: { “状态”:空, "message": "无效的手机号码,需要 10 位数字" }

【问题讨论】:

  • $this->post() 不是 codeigniter 中的函数。似乎您可能在没有明确提及的情况下引用了外部库。
  • $this->post() 在 REST_Controller 中定义,我从中扩展我的控制器。您可以从此链接获取有关此架构的更多详细信息。 code.tutsplus.com/tutorials/…

标签: php rest codeigniter


【解决方案1】:

我整理好了。由于 post 数据为空,请求者没有传递请求正文中的数据,也没有传递查询字符串参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-11
    • 1970-01-01
    • 2012-09-04
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多