dousuiben8395 2016-12-30 16:27
浏览 61
已采纳

Codeigniter - 以admin身份编辑用户

Working user manage page with codeigniter, I made edit user function my self and that works but notification can't working. Mean If problem in updating user detail that should through error or Success but nothing happening but datas are updating.

Here is Model(Admin_model.php):

public function editUser($id, $data)
{

    $this->db->where('id', $id);
    $this->db->update('users', $data);
}

controller(Admin.php):

public function edit_user($id) 
{

    //set validation rules
    $this->form_validation->set_rules('firstname', 'First Name', 'trim|required');
    $this->form_validation->set_rules('lastname', 'Last Name', 'trim|required');
    $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');

    if ($this->form_validation->run() == FALSE)
    {

        $this->load->view('default/admin/edit_user');

    } else {

        $data = array(
            'firstname' => $this->input->post('firstname'),
            'lastname'  => $this->input->post('lastname'),
            'email'     => $this->input->post('email'),
            'updated_at' => date('Y-m-j H:i:s')
        );

        if($this->Admin_model->editUser($id,$data)) {
            $this->session->set_flashdata('global_alert','<div class="alert alert-success text-center">User updated!</div>');
            redirect('admin/users');
        } else {
            $this->load->view('default/admin/edit_user');

            $this->session->set_flashdata('global_alert','<div class="alert alert-danger text-center">Something wrong!</div>');
        }

    }

}
  • 写回答

1条回答 默认 最新

  • douxun4860 2016-12-30 19:50
    关注

    $this->Admin_model->editUser is not returning anything. try

    public function editUser($id, $data)
    {
    
        $this->db->where('id', $id);
        $result = $this->db->update('users', $data);
        if ($result === FALSE)
        {
            show_error('error !');
        }
        return $result;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?