0
的Controler笨更新記錄
//class News
public function update($slug)
{
$this->load->helper('form');
$this->load->library('form_validation');
$data['news_item']=$this->news_model->get_news($slug);
if (empty($data['news_item']))
{
show_404();
}
$data['title'] = $data['news_item']['title'];
$this->load->view('templates/header', $data);
$this->load->view('news/update', $data);
//$this->load->view('save',$save);
$this->load->view('templates/footer');
}
模型new_model.php下面
//class News_model
public function get_news($slug = FALSE)
{
if($slug === FALSE)
{
$query = $this->db->get('news');
return $query->result_array();
}
$query = $this->db->get_where('news',array('slug'=>$slug));
return $query->row_array();
}
public function update_news($slug)
{
$query=$this->db->where('slug', $slug);
$this->db->update('news' ,$query);
return $query->row_array();
}
在update.php視圖文件代碼
給出.. 視圖update.php文件
<h2>Update New Item</h2>
<?php echo form_open('news/update') ?>
<label for="title">Title</label>
<input type="input" name="title" value="<?php echo $news_item['title']; ?>" readonly/><br>
<label for="text">Text</label>
<textarea name="text" cols="35" rows="16"><?php echo $news_item['text'];?></textarea><br>
<a href="save/">save</a>
</form>
數據將被抓取,但有問題的是,當我點擊「保存」鏈接頁面沒有找到錯誤generatos爲什麼? 怎麼稱呼這種觀點save.php文件..
你在這個代碼在做什麼?我不明白。你可以解釋嗎? –
要保存表單,只需提交一個提交輸入,如,則鏈接將只是將頁面重定向到另一個url。 – Andrew