use active records in library |
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?
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){
Here is a template for creating a Custom Library.
PHP Code: class Custom_Library { What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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));
Also just a note:
It's called Query Builder now not Active Records. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |