Model view controller 向模型发送分段的最佳实践?

Model view controller 向模型发送分段的最佳实践?,model-view-controller,codeigniter,Model View Controller,Codeigniter,我想知道在将片段发送到模型之前的最佳实践是什么 例如: 从中获取分段1 基本url/控制器/查询详细信息/分段1 在我的控制器上 public function query_detail($segment1) { //what are the best practice before I send the segment1 to the Model? $this->load->model('model'); $this->model->query($segme

我想知道在将片段发送到模型之前的最佳实践是什么

例如:

从中获取分段1 基本url/控制器/查询详细信息/分段1

在我的控制器上

public function query_detail($segment1)
{
//what are the best practice before I send the segment1 to the Model?
   $this->load->model('model');
   $this->model->query($segment1);   
   ......  
} 

我希望我能解释清楚。感谢您的帮助。

如果您指的是向模型发送数据以使用该数据运行插入或更新,那么最佳做法是在用户提交输入时验证输入。然后,因为codeigniter在用作绑定数据时会清理数据,所以您可以运行这样的插入

# This would be in your model...not your controller
function store_data($post_data) {
  $sql = "INSERT INTO some_table set (fld1, fld2, fld3) VALUES (?, ?, ?)";
  $binds = array($post_data['fld1'], $post_data['fld2'], $post_data['fld3']);
  $this-db->query($sql, $binds);
}
或者,如果所有传入表单的输入标记名都与数据库列名匹配,则可以简单地执行此操作

# This would be in your model...not your controller
function store_data($post_data) {
  $sql = "INSERT INTO some_table set (fld1, fld2, fld3) VALUES (?, ?, ?)";
  $binds = array($post_data);
  $this-db->query($sql, $binds);
}
或者这个,

# This would be in your model...not your controller
# Using ActiveRecord
function store_data($post_data) {
  $this->db->insert('some_table', $post_data);
}

对不起,没什么意义。正是我需要的。谢谢Skittles。