Codeigniter help needed for user permissions

Discussion in 'PHP' started by gadgetpro, Jul 30, 2010.

  1. #1
    Hello, I'm in the midst of creating an admin backend panel for my new website, but I've come across a road-bump..

    I have a table in my database with all the users, and one of the fields is 'rank' with as value either admin, user, or moderator.

    When logging in, I would like to pull the user's rank, and storing it into the session that gets created. When using activerecords, I've only managed to pass the ARRAY through to the session. Although the only thing in the array is the rank of the user, I'd like to pass the actual RANK of the user into the session.

    Any help would be greatly appreciated!

    Thanks in advance,

    Alex
     
    gadgetpro, Jul 30, 2010 IP
  2. ze0xify

    ze0xify Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The above post is awesome. Just FYI.

    So for what you would like:

    This would be some example model code:
    public function get_user($username)
    {
    $this->db->select('*');
    $this->db->from('users');
    $this->db->where('username', $username);
    $this->db->limit(1);
    $result = $this->db->get();
    return $result->row();
    }
    PHP:
    This would be controller code, after including your model to it (or writing this in a library)
    $user = $this->modelname->get_user('ze0x');
    $this->session->set_userdata('rank', $user->rank);
    PHP:
    I hope I explained how to do this well enough. Feel free to add me on MSN if you'd like additional help. I've been working with Codeigniter for two years now.
    MSN:
     
    ze0xify, Jul 31, 2010 IP
  3. gadgetpro

    gadgetpro Peon

    Messages:
    147
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank you! I hadn't thought of the limit and just setting the row as the return value.
     
    gadgetpro, Aug 1, 2010 IP