【问题标题】:Get response after submitted提交后得到回复
【发布时间】:2019-12-03 04:36:09
【问题描述】:

我有 CI 控制器使用 json 提交数据,我的计划是在响应消息中显示提交的数据,这里是我的控制器的代码:

            public function add_post()
    {
        $this->is_allowed('api_tbl_driver_task_add', false);

        $id = $this->get('task_id');
        $this->form_validation->set_rules('customer_id', 'Customer Id', 'trim|required|max_length[14]');
        $this->form_validation->set_rules('task_description', 'Task Description', 'trim|required|max_length[255]');
        $this->form_validation->set_rules('trans_type', 'Trans Type', 'trim|required|max_length[255]|in_list[installation]');
        $this->form_validation->set_rules('contact_number', 'Contact Number', 'trim|required|max_length[50]');
        $this->form_validation->set_rules('customer_name', 'Customer Name', 'trim|required|max_length[255]');
        $this->form_validation->set_rules('imei', 'Imei', 'trim|required|max_length[11]');

        if ($this->form_validation->run()) {

            $save_data = [
                'customer_id' => $this->input->post('customer_id'),
                'task_description' => $this->input->post('task_description'),
                'trans_type' => $this->input->post('trans_type'),
                'contact_number' => $this->input->post('contact_number'),
                'customer_name' => $this->input->post('customer_name'),
                'imei' => $this->input->post('imei'),
                //'task_token' =>$this->setToken(sha1(rand(11111, 99999));,
            ];

            $save_tbl_driver_task = $this->model_api_tbl_driver_task->store($save_data);

            if ($save_tbl_driver_task) {
                $this->response([
                    'status'    => true,
                    'message'   => 'Data saved',
                    //'task_id'     => true,
                    'task_id'       = $this->get($id, true),
   //'task_id' =>     print_r($this->input->post('name'),

                ], API::HTTP_OK);

我想在消息旁边的 json 响应中打印 task_id。尝试使用 'task_id' => json_decode($this->get($id)), 但没有运气

非常感谢您的任何建议

【问题讨论】:

  • 检查$id是否在范围内可用,并且它是一个有效值。
  • $this->get($id) 返回什么? JSON?请显示函数'get'结果。
  • 嗨 @ocBierman 是的,在循环功能下可用。
  • @Elena Vasilenko 它返回 null :(
  • @Bireon 你的函数$this->get($id) 做什么?显示它的代码。

标签: php json codeigniter


【解决方案1】:

最后,代码使用返回值。问题解决了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-12
    • 2017-05-10
    • 1970-01-01
    • 2017-03-14
    • 2020-04-29
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多