2014-04-01 115 views
1

當前,編輯配置文件適用於我。但是,我的問題是,只有一個元素被成功編輯。我可以回顯以前保存的數據,我甚至可以鍵入和編輯每個文本框。問題是,只有在「配置文件」字段上進行的修改才能得到適當的反映。所有其他領域保持不變。在Codeigniter中編輯多個字段

這裏是我到目前爲止有: 在控制器頁:

public function edit_profile() 
{ 
    //loads client profile and allows editing to be done 
    $this->validateRole('client'); 
    $this->load->model('job_model'); 

    $id = $this->auth_model->get_user_id(); 

    $data['client'] = $this->auth_model->get_client($id); 
    $this->load->view('client/edit_profile', $data); 
} 
public function edit_profile_submit() 
{ 
    $this->validateRole('client'); 
    $this->load->model('auth_model'); 
    //$this->auth_model->edit_client_profile($this->auth_model->get_user_id(), $_POST['tagline']);  
    $this->auth_model->edit_client_profile($this->auth_model->get_user_id(), $_POST['profile']); 
    //$this->auth_model->edit_client_profile($this->auth_model->get_user_id(), $_POST['billing_mode']); 
    redirect('client/view_profile?message=Profile updated.'); 

} 

模型頁:

public function edit_client_profile($id, $profile) 
{ 
    // allows client to edit his or her profile 
    $data = array(
     //'tagline' => $tagline, 
     'profile' => $profile 
     //'billing_mode' => $billing_mode 
    ); 
    $this->db->where('id', $id); 
    $this->db->update('client', $data); 
} 

我試圖編輯我的控制器和模型頁面,讓我評論了只得到錯誤現在改爲添加行。 我期待着任何可能的幫助。

謝謝!

+0

不要分別調用edit_client_profile三次。在您的控制器中創建一個包含鍵值'tagline','profile'和'billing_mode'的數組。然後將所有數據發送到您的edit_client_profile函數。 – Dan

回答

0

錯誤可能是因爲每次調用模型時,您的$ data數組中都有兩個未定義的變量。相反,在你的模型創建陣列的,在你的控制器創建它:

$data = array(
    'tagline' => $_POST['tagline'], 
    'profile' => $_POST['profile'], 
    'billing_mode' => $_POST['billing_mode'] 
); 

然後調用模型

$this->auth_model->edit_client_profile($this->auth_model->get_user_id(), $data); 

從模型中取出數組創建,更改第二個參數傳遞給$data

public function edit_client_profile($id, $data) 
{ 
    $this->db->where('id', $id); 
    $this->db->update('client', $data); 
} 
+0

非常感謝!我知道了!它正在工作!非常感謝!但唯一的問題是計費模式(應該從下拉菜單中選擇)現在不反映任何內容。如果您也可以幫助我,那麼我將不勝感激。但是我也會嘗試我的運氣。再次感謝。祝你有美好的一天! ;) – user3453256

+0

最好的辦法是在下拉列表http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html查看codeigniter文檔。很高興幫助...如果問題得到解決,請接受答案 – Dan

+0

確實如此。再次感謝你的幫助!祝你有美好的一天,丹尼爾!:) – user3453256