2010-12-20 122 views
0

如何在編輯(更新)數據庫中的條目時獲取表單域內容?如何在編輯時在codeigniter中回顯數據庫內容

我CONTROLER是

//edit sidebar contents 
function edit_lsidebar(){ 

     if(isset($_POST['heading'])){ 
     //adding text fields 
     $heading = $this->input->post('heading'); 
     $content_text = $this->input->post('content_text'); 
     $url = $this->input->post('url'); 
     $link_text = $this->input->post('link_text'); 

     $this->Lside_bar_model->edit_lsidebar($heading, $content_text, $url, $link_text); 

     redirect('welcome'); 
    } 
    else $this->load->view('edit_lside_bar', $data);  
} 

我的模型是

function edit_lsidebar($heading, $content_text, $url, $link_text){  
    $data = array(
    'heading'=>$heading, 
    'content_text'=>$content_text, 
    'url'=> $url, 
    'link_text' => $link_text 
    ); 

    $this->db->where('id',$this->uri->segment(3)); 
    $this->db->update('lsidebar', $data); 

} 

請幫助

+3

你能解釋一下你有什麼問題嗎?我不太明白你的問題! – musoNic80 2010-12-20 18:00:56

+0

如何在表單字段中編輯(更新記錄)時顯示數據庫字段內容? – ktm 2010-12-21 04:34:33

+2

解釋*更*,請不要重複相同的模糊的事情 – Ross 2010-12-21 08:58:01

回答

0

當加載您edit_lside_bar視圖通過現有$標題,$ content_text,$網址,$ LINK_TEXT變量用你傳遞給視圖的數據數組。

然後在視圖內部將這些值回顯爲輸入字段的值屬性。例如:

內部控制器:

else { 

$data["lside_bar"] = $this->Lside_bar_model->get_lside_bar($id); 
$this->load->view('edit_lside_bar', $data); 

} 

內,您的看法:

<input type="text" name="heading" value="<?php echo $lside_bar->heading; ?>" /> 
<textarea name="content_text"><?php echo $lside_bar->content_text; ?></textarea> 
.... 

這應該給你一個正確的方向漂亮的推動。希望有所幫助!