Php 如何在同一文件中的另一个类内使用其他类方法?
我有一个场景,我必须使用一个类来扩展另一个类,而这个类不是codeigniter类,在这个方法内部,我需要调用另一个方法来执行数据库操作 我怎样才能做到Php 如何在同一文件中的另一个类内使用其他类方法?,php,codeigniter,class,Php,Codeigniter,Class,我有一个场景,我必须使用一个类来扩展另一个类,而这个类不是codeigniter类,在这个方法内部,我需要调用另一个方法来执行数据库操作 我怎样才能做到 <?php require_once(APPPATH.'third_party/OauthPhirehose.php'); class Get extends CI_Controller { function __construct() { parent::__construct();
<?php
require_once(APPPATH.'third_party/OauthPhirehose.php');
class Get extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('tweets_model');
}
public function getall()
{
$tags = $this->tags_model->get();
$result = $tags->row();
$first = $result->first_tag;
$second = $result->second_tag;
return array($first, $second);
}
public function insert_raw_tweet($raw_tweet, $tweet_id)
{
$this->tweets_model->save_raw($raw_tweet, $tweet_id);
}
}
class Consume extends OauthPhire {
public function enqueueStatus($status) {
$tweet_object = @json_decode($status);
if (!(isset($tweet_object->id_str))) { return;}
$tweet_id = $tweet_object->id_str;
$raw_tweet = base64_encode(serialize($tweet_object));
echo $tweet_object->text . "\r\n";
// here i need to use top class method to insert data
//$this->tasks->insert_raw_tweet($tweet_object, $tweet_id);
}
}
$get_track = new Get();
$list = $get_track->getall();
$stream = new Consume(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER);
$stream->setTrack($list);
$stream->consume();
加载它就像加载存储在/library/folder中的普通第三方库一样,请使用以下方法:
$this->load->library('OauthPhirehose');
希望这能奏效