Welcome Guest, Not a member yet? Register   Sign In
use active records in library
#2

Libraries are a little different in they don't have immediate access to the `$this` super global.

There's a couple ways to do it but here's how most will tell you to...
PHP Code:
public function __construct()
    {
        
$ci = &get_instance();
    } 


Then, anywhere you use '$this->' use '$ci->' instead,

for example:
PHP Code:
public function userExists($id){
 
       $query $ci->db->get_where('users', array('id' => $id));
 
       $number $query->num_rows();
 
       if($number 0)
 
           return true;
 
       else
            return false
;
 
   
Reply


Messages In This Thread
use active records in library - by Valerekk - 10-21-2017, 07:10 PM
RE: use active records in library - by enlivenapp - 10-21-2017, 07:41 PM
RE: use active records in library - by Valerekk - 10-22-2017, 06:22 AM
RE: use active records in library - by InsiteFX - 10-22-2017, 03:29 AM
RE: use active records in library - by InsiteFX - 10-23-2017, 08:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB