【发布时间】:2018-01-05 07:25:18
【问题描述】:
对于在 CodeIgniter 3.1.5(最新版)中遵循在控制器或模型中发布和处理数据的有效方式有点困惑
方法:1 在模型中
public function insert_entry()
{
$this->title = $_POST['title'];
$this->content = $_POST['content'];
$this->date = time();
$this->db->insert('entries', $this);
}
方法:2 在控制器中
public function insert_entry()
{
$title = $this->input->post("title");
$content = $this->input->post("content");
$date = $this->input->post("date");
$data = array(
'title' => $title,
'content' => $content,
'date' => $date
);
$this->model->insert($data);
}
然后在模型中处理数据和查询。
如果我们正在创建大型 Web 应用程序,这是一种有效的方法。
【问题讨论】:
标签: php codeigniter codeigniter-3