0

呃,我仍然无法理解表格。我看过一些指南/视频,但没有运气(请记住,我跑步时睡眠不足)所以我想我可以在这里寻求帮助。

假设我有一个名为 Notes 的表,在 Notes 表中我有一个名为“user”和“note”的列

我只是想使用表单和提交按钮编辑 Notes 表中的“注释”和“用户”。

有人可以把控制器和模型的样子放在一起吗?我知道我问了很多,所以我很感激你的时间。

编辑1

我的模型:

function edit($id)
{
          $this->db->where('id', $id);
          $this->db->update('company_contacts', $data);

}

控制器:

public function edit($id) { 
            if (isset($_POST["edit"]))
            {
                $this->Notes_model->edit($id);
                $url = "/notes/view/" . $id;
                redirect($url);
            }
        $data['data']  = $this->Notes_model->view($id);
        $this->load->view('templates/header');
        $this->load->view('notes/edit', $data);
        $this->load->view('templates/footer');
   }
4

2 回答 2

0

这就是我会做的。当我使用助手时,该方法与您所做的有点不同。要使用我的代码,您需要input启用助手。

控制器

public function edit($id) { 
  if (isset($this->input->post('edit'))
  {
    $this->load->model('Notes_model'); // You might have missed out on loading the model

    // Since you wish to edit the note and user fields in your table, you need to get the value from the page you are submitting the request from
    $note = $this->input->post('note');
    $user = $this->input->post('user');

    $data = array(
      'note' => $note,
      'user' => $user
    );

    $this->Notes_model->edit($id, $data);
    $url = "/notes/view/" . $id;
    redirect($url);
  }
  $data['data']  = $this->Notes_model->view($id);
  $this->load->view('templates/header');
  $this->load->view('notes/edit', $data);
  $this->load->view('templates/footer');
}

模型

function edit($id, $data)
{
  $this->db->where('id', $id);
  $this->db->update('company_contacts', $data);
}
于 2013-06-12T13:28:45.137 回答
-1

尝试这个。

你的模型应该是

function edit($id)
{
    $data = array(
               'note' => $_POST['note'],
               'user'=> $_POST['user']// I don't think you need this. 
            );

     $this->db->where('id', $id);
     $this->db->update('company_contacts', $data);

}
于 2013-06-12T03:13:16.917 回答