When I or user logs on it checks what permissions it has. And then on a form if has not got permission throws error.

Example:

<?php

class Users_groups extends CI_Controller {

public function update() {
   if (($this->input->server('REQUEST_METHOD') == 'POST') && $this->validateForm()) {
      // Modal stuff
   }
}

public function index() {
 // form content
}

public function validateForm() {
    if (!$this->user_auth->hasPermission('modify', 'user/Users_groups')) {
        $this->error['warning'] = 'You do not have permission to modify';
    }

    return !$this->error;
}

}

When I submit form it should let me edit and save but for some reason this

if(isset($value))  {return $value==$this->permission[$key];}

is not working so when I submit my form it throw error.

Severity: Notice

Message: Undefined index: modify

Filename: libraries/User_auth.php

Line Number: 65

Line 65 is this

if(isset($value))  {return $value==$this->permission[$key];}

I do not know why not working way it should I am confused.

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_auth {

private $permission = array();
private $user_id;
private $username;

public function __construct() {
    $this->CI =& get_instance();
    $this->CI->load->model('admin/user/model_user_user');
    $this->CI->load->library('session');
}


/**
 * @return bool
 */
public function login() {

    $this->CI->db->where('username', $this->CI->input->post('username'));
    $user_query = $this->CI->db->get('user');

    if ($user_query->num_rows() > 0) {

        $row = $user_query->row();

        $this->CI->db->select('permission');
        $this->CI->db->from($this->CI->db->dbprefix .'user_group');
        $this->CI->db->where('user_group_id', $row->user_group_id);
        $user_group_query = $this->CI->db->get();

        if ($user_group_query->num_rows() > 0) {

            $permissions = unserialize($user_group_query->row('permission'));

            if (!is_array($permissions)) {
                foreach ($permissions as $key => $value) {
                    $this->permission[$key] = $value;
                }
            }

        } else {
            return false;
        }

        if ($this->CI->model_user_user->check_password($this->CI->input->post('password'), $user_query->row('password'))) {
            return true;
        } else {
            return false;
        }

    } else {
        return false;
    }

}

/**
 * @param $key
 * @param $value
 * @return bool
 */
public function hasPermission($key, $value) {
    if(isset($value))  {return $value==$this->permission[$key];}

    return false;
}

public function getId() {
    return $this->user_id;
}

public function getUsername() {
    return $this->username;
}

}

am not good in Codeigniter but i came by on this problem in simple script,
for permission[$key] array try to check if there is a value before processing,
from your example permission['modify'] is not found
if(isset(permission['modify'])) then do stuff.

I tried that earlier and same result. Very strange. Even though I have permission to edit. Still throughs error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.