我有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);
我想在message旁边的json响应中打印task_id。尝试使用'task_id' => json_decode($this->get($id)),
但没有运气
非常感谢您的任何建议
答案 0 :(得分:0)
最后,代码可以返回值。问题解决了!