dongza5150
dongza5150
2017-11-17 04:15
浏览 91

在CodeIgniter中使用$ _POST值

Application makes an AJAX request to a method in a controller.

The controller then calls a method in the model to run a query on the DB and then return the results.

AJAX "type" specified as POST.

Even though $_POST superglobal values are available for use in model, should one still list the $_POST values in the model method signature?

I'm thinking this is best practice so people dissecting a system can quickly see inputs going into model methods

$this->Students_table_model->attendance_history_get($_POST['students_id'],$_POST['start_date'],$_POST['end_date']);

public function attendance_history_get($students_id,$start,$end)

VS

$this->Students_table_model->attendance_history_get();

and then just using the available $_POST values in model method attendance_history_get()

图片转代码服务由CSDN问答提供 功能建议

应用程序向控制器中的方法发出AJAX请求。

然后,控制器调用模型中的方法在DB上运行查询,然后返回结果。

指定为POST的AJAX“type”。

即使$ _POST超全局值可用于模型,是否仍然会在模型方法签名中列出$ _POST值?

我认为这是最佳实践,因此人们解剖 系统可以快速查看进入模型方法的输入

  $ this-> Students_table_model-> attendance_history_get($ _ POST ['students_id'],$ _ POST ['start_date']  ,$ _ POST ['end_date']); 
 
公共函数attendance_history_get($ students_id,$ start,$ end)
   
 
 

VS $ this-> Students_table_model-> attendance_history_get();

然后只使用模型方法中的可用$ _POST值 attendance_history_get()

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douyuan3842
    douyuan3842 2017-11-17 04:44
    已采纳

    I think you should use the codeigniter custom function $this->input->post(); to get the post value

    $student_id = $this->input->post('students_id');
    $start_date = $this->input->post('start_date');
    $end_date = $this->input->post('end_date');
    
    点赞 评论
  • dounianji7883
    dounianji7883 2017-11-17 05:25

    Use

    $this->Students_table_model->attendance_history_get($_POST);
    

    and use it in the model.

    点赞 评论

相关推荐