CodeIgniter Forums
[Fixed] Totally stumped on this (minor mod to Erkana getRole method) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: [Fixed] Totally stumped on this (minor mod to Erkana getRole method) (/showthread.php?tid=5444)



[Fixed] Totally stumped on this (minor mod to Erkana getRole method) - El Forum - 01-21-2008

[eluser]awpti[/eluser]
I didn't like the logic of how getRole() worked, so I changed it to return true/false (makes more sense than returning the actual result to me).

Code:
function get_role($role)
        {
                $this->CI->db->select('otn_roles.name');
                $this->CI->db->JOIN('otn_roles', 'otn_users.role_id = otn_roles.id');
                $query = $this->CI->db->getwhere('otn_users', array('otn_users.id'=>$this->CI->session->userdata('user_id')), 1, 0);
                $row = $query->result();
                if ($row->name === $role)
                {
                        return TRUE;
                }
                else
                {
                        return FALSE;
                }
        }

if($row->name === $role).. returns:

Severity: Notice
Message: Trying to get property of non-object
Filename: libraries/Erkanaauth.php
Line Number: 136

I don't get it. var_dump of $row:

array(1) { [0]=> object(stdClass)#26 (1) { ["name"]=> string(5) "admin" } }

What the heck am I missing?


[Fixed] Totally stumped on this (minor mod to Erkana getRole method) - El Forum - 01-21-2008

[eluser]awpti[/eluser]
Found my problem.

I was using ->result() when i should have used ->row()

I need some caffine.