johnmerlino Posted March 6, 2011 Share Posted March 6, 2011 Hey all, In my controller I have this: public function __construct(){ parent::Controller(); $this->load->model('home'); } public function index(){ $result = Home::find('all'); } In model this: public function __construct(){ parent::Model(); } public static function find($param){ if(is_null($param) || $param === 'all'){ $resources = $this->db->get('home'); //but I can't do self::db - because db is not a static property of the Home class, which is what self is pointing to. return $resources->result(); } return null; } } Since $this property is a reference to an object (a new instance), and a static method is not an instance, but a class method, I must use self and not this in the function block. However, the db property codeigniter provides cannot be called as a static property, since it was not declared as such. So when I get the error: Fatal error: Access to undeclared static property: Home::$db or Fatal error: Using $this when not in object context I am not sure what to do. Thanks for response. Quote Link to comment https://forums.phpfreaks.com/topic/229732-using-codeigniter-activerecord-properties-within-a-static-method/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.