CodeIgniter-Authit icon indicating copy to clipboard operation
CodeIgniter-Authit copied to clipboard

user() helper

Open mflash123 opened this issue 8 years ago • 3 comments

I need use in input forms user($key) value. But, sometimes, that key is NULL or doesnt exist, so I get error notice about non exist key. So, I made some upgrade to return NULL if key doesnt exist.

mflash123 avatar May 27 '18 22:05 mflash123

Ok, so this wouldn't be an issue for custom handling.

trafficinc avatar May 27 '18 22:05 trafficinc

I didnt understand how to make pull-request..so, this is simple improvement: authit_helper.php:

function user($key = NULL)
{
	$CI =& get_instance();
	$CI->load->library('session');
	
	$user = $CI->session->userdata('user');
	if(!is_null($key))
	{
		if($key && isset($user->$key))
		{
			return $user->$key;
		} else {
			return NULL;
		}
	}
	return $user;
}

mflash123 avatar May 28 '18 09:05 mflash123

With this [user] function it is supposed to return the whole user object if the key is NULL and the related key for the object if the "key" is present, so with your code, you would be returning NULL when there are no specified keys, which is not the intended functionality. To use this correctly, save a user associative array cast to an object to the session, then you can pull the currently logged in user by leaving the key as NULL, or specify the key to get just the key.

trafficinc avatar May 29 '18 16:05 trafficinc