CI 2.1での更新に問題があります。ユーザーガイド「mini-tut」に従ってeニュースを作成しましたが、フォームを使用してレコードを更新する方法がわかりません。
私の更新モデルは次のとおりです。
// update dei record
public function update_news($id)
{
$data = array(
'title' => $this->input->post('title'),
'slug' => $this->input->post('slug'),
'text' => $this->input->post('text')
);
$this->db->where('id', $id);
$this->db->update('news', $data);
}
コントローラーを更新するにはどうすればよいですか?私は試してみます:
public function update($id)
{
$this->load->helper('form');
$this->load->library('form_validation');
$data['title'] = 'Update an intem';
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('text', 'text', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header', $data);
$this->load->view('news/update');
$this->load->view('templates/footer');
}
else
{
$this->news_model->update_news($id);
$this->load->view('news/success');
}
}
しかし、私は404()ページを表示します。
更新のビューは次のとおりです。
<h2>Update an item</h2>
<?php echo validation_errors(); ?>
<?php echo form_open('news/update') ?>
<label for="title">Title</label>
<input type="input" name="title" /><br />
<label for="slug">Slug</label>
<input type="input" name="slug" /><br />
<label for="text">Text</label>
<textarea name="text"></textarea><br />
<input type="submit" name="submit" value="Update an item" />
</form>
CIロジックを理解するための「単純な」更新方法を教えてくれる人はいますか?