2015-09-27 217 views
0

我有一个场景,我不得不使用一个类来扩展另一个类,它不是一个codeigniter类和方法内部,我需要调用另一个方法来执行数据库操作。如何在同一文件的其他类中使用其他类方法?

我该如何实现?

<?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(); 

回答

0

加载它,就像你加载存储在/ Library /文件夹,正常的第三方库,使用此方法:

$this->load->library('OauthPhirehose'); 

希望这个作品。