Codeigniter仅编辑自己的配置文件作为用户

时间:2017-09-14 13:19:05

标签: php codeigniter

我有一个问题,我可以编辑所有配置文件作为用户。但我想,我只能编辑我的个人资料。也许你可以帮助我。如果我想编辑我的个人资料,如

,代码正常工作

域/构件/用户/管理/ 1

但我也可以编辑/ member / users / manage / 2,这就是问题所在。

Controller Users.php

public function manage($id = NULL) {

        if($this->session->userdata('type') == 'user') {

        $data = array();

        if ($id) {
            $this->{$this->model}->{$this->_primary_key} = $id;
            $data['item'] = $this->{$this->model}->get();
            if (!$data['item'])
                show_404();
        } else {
            $data['item'] = new Std();
        }


        $this->load->library("form_validation");
        $this->form_validation->set_rules('username', 'Username', 'trim|required');

        $this->{$this->model}->custom_select = 'users.*, teams.title as teams';
        $this->{$this->model}->joins = array( 'teams' => array('teams.teams_id = users.teams_id', 'inner'));

        $this->form_validation->set_rules('firstname', 'firstname', 'trim|required');
        $this->form_validation->set_rules('lastname', 'lastname', 'trim');
        $this->form_validation->set_rules('sex', 'sex', 'trim');
        $this->form_validation->set_rules("image3", 'image3', "trim|callback_image3[$id]");

        $this->form_validation->set_rules("email", 'Email', "trim|required|valid_email");
        if ($id)
            $this->form_validation->set_rules('password', 'Password', 'trim');
        else
            $this->form_validation->set_rules('password', 'Password', 'trim');


        if ($this->form_validation->run() == FALSE)
            $this->load->view($this->module . '/manage', $data);

        else {
            $this->users_model->username = $this->input->post('username');
            $this->users_model->email = $this->input->post('email');

            $this->users_model->firstname = $this->input->post('firstname');
            $this->users_model->lastname = $this->input->post('lastname');
            $this->users_model->sex = $this->input->post('sex');

            if (strlen($this->input->post('password')) > 0)
                $this->{$this->model}->password = md5($this->input->post('password'));

            $this->{$this->model}->save();
            redirect('member/' . $this->module);
        }

        }else{
            exit('Hacking Attempt: Get out of the system ..!');
        }

    }

Users_model.php

<?php

class Users_model extends CI_model
{
    public $_table = 'users';
    public $_primary_keys = array('user_id');


}

1 个答案:

答案 0 :(得分:0)

第一个你必须在会话中传递user_id

然后需要domain/member/users/manage/1

您重定向到个人资料...

如果用户控制器具有功能管理

class Users extends CI_Controller
{
  public function manage($userid)
  {
   #checking the with session value
   if(($this->session->userdata('user_id')!=$userid)):
      #if not satisfied means redirect another page
      redirect("Another page");
   endif;
  }
}