![]() |
use active records in library - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: use active records in library (/showthread.php?tid=69224) |
use active records in library - Valerekk - 10-21-2017 Hello, i'm writing my personal library for Users. but i have a problem trying to query my db. is wrong call db from Lib? PHP Code: Class User obviously in my controller i loaded the lib with PHP Code: $this->load->library('user'); the error is Code: A PHP Error was encountered is a good way? RE: use active records in library - enlivenapp - 10-21-2017 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() Then, anywhere you use '$this->' use '$ci->' instead, for example: PHP Code: public function userExists($id){ RE: use active records in library - InsiteFX - 10-22-2017 Here is a template for creating a Custom Library. PHP Code: class Custom_Library { RE: use active records in library - Valerekk - 10-22-2017 PHP Code: public function userExists($id){ Thanks guys.. the only correction i've done is row number 2 PHP Code: $query = $ci->db->get_where('users', array('id' => $id)); PHP Code: $query = $this->ci->db->get_where('users', array('id' => $id)); RE: use active records in library - InsiteFX - 10-23-2017 Also just a note: It's called Query Builder now not Active Records. |