[英]How to use other class methods inside of another class in same file?
I've a scenario where i have to use a Class that extends another class which is not a codeigniter class and inside of the method, i need to call another method to perform Database operation. 我有一种情况,我必须使用扩展了不是Codeigniter类的另一个类的类,并且该方法内部需要调用另一个方法来执行数据库操作。
How can i achieve? 我该如何实现?
<?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();
Load it just like you load a normal third party library stored in /library/ folder, use this method : 加载它就像加载存储在/ library /文件夹中的普通第三方库一样,请使用以下方法:
$this->load->library('OauthPhirehose');
Hope this works. 希望这行得通。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.