目前,编辑个人资料对我有用。但是,我的问题是,只有一个元素被成功编辑。我可以回显以前保存的数据,我甚至可以输入和编辑每个文本框。问题是,只有对" profile"进行了修改。字段被正确反映。所有其他领域保持不变。
这是我到目前为止所拥有的: 在控制器页面中:
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 :(得分: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);
}