[eluser]Morgan Cheng[/eluser]
I'm ramping up with Twitter API. I found that below code doesn't work.
Code:
class TimeLine_Model extends Model {
public function __construct() {
parent::__construct();
$this->load->library('twitter');
$this->twitter->auth('username', 'password');
}
function getFriendsTimeLine() {
$timeline = $this->twitter->call('statuses/friends_timeline');
return $timeline;
}
}
The error is indicating that "$this->twitter" in constructor is null.
Quote:: Call to a member function auth() on a non-object in ....\***.php on line 8
It seems that
Code:
$this->load->library
doesn't work in constructor. Why?
I originally plan to make a customized MY_Model and have
initialized in the constructor. Then, all my models can inherits from that MY_Model.
If
Code:
$this->load->library
doesn't work in constructor. How to workaround it?