[eluser]n0xie[/eluser]
I'll try to answer.
Let's step to the process of what happens and hopefully you will see where you went wrong and learn something in the process
So we start with your Controller:
Code:
//snippet
$this->load->model('Twitter_model');
$data['tweet'] = $this->Twitter_model->insert_tweet();
First it loads the model. This is fine.
Next line what you basically tell your application to do is this:
Quote:Assign the output of the method 'insert_tweet' from the model 'Twitter_model' to my array/key '$data['tweet'].
So your application tries to execute the method 'insert_tweet', just like you tell it to. At this point we look at your model:
Code:
// snippet
function insert_tweet(){
foreach($tweet as $t) {}
Now the model at this point has no way of knowing who or what '$tweet' is, because you didn't tell it what it is.
So what you need to do is tell your model what '$tweet' is. You can do this in several different ways. First you need to fetch the tweets from Twitter, else you have nothing to work with and then pass this information to your model so it knows what it needs to insert into your database. After that you want to retrieve your data from the database in some order which you can alter. I'll make a quick example:
Code:
// controller
$this->load->model('Twitter_model');
$tweet = $this->Twitter_model->get_tweet();
$this->Twitter_model->insert_tweet($tweet);
$data['tweet'] = $this->Twitter_model->get_tweet_from_db();
// model
function insert_tweet($tweet){
foreach($tweet as $t) {
$tweet = array(
'user' => $t->user->name ,
'pic' => $t->user->profile_image_url ,
'time' => $t->user->created_at ,
'tweet' => $t->text
);
}
$this->db->insert('updates',$tweet);
}
function get_tweet_from_db()
{
// get some data from the database ordered however you want
}
Hope this was clear and helps. All example code is untested, but should point you in the right direction.