Reputation: 2860
I have a PHP class which is supposed to return an array to where the object is instantiated. I have tried to figure out what the problem is but I can't seem to see it. Can anyone see where I have gone wrong here or point me in the right direction? Thanks
Here is the class (within a file called 'feeds.php.)
class updateFeed {
public function index() {
$db = JFactory::getDBO();
$query = "SELECT * FROM tweets";
$db->setQuery($query);
$result = $db->loadObject()
if(strtotime($result->date_added) <= time() - 3200) {
$this->updateTweets();
}
$query = "SELECT * FROM tweets ORDER BY tweet_date DESC LIMIT 0, 3";
$db->setQuery($query);
$results = $db->loadObjectList();
$tweet_db = array();
foreach($results as $result) {
$tweet_db[] = array(
'title' => $result->title,
'text' => $result->text,
'tweet_date' => $result->tweet_date
);
}
return $tweet_db;
}
And here is where the object is instantiated (in the index.php file):
include('feeds.php');
$tweet_dbs = new updateFeed;
print_r($tweet_dbs);
The print_r in the index file shows 'updateFeed Object ( ) '. Thanks in advance.
Upvotes: 0
Views: 3672
Reputation: 2561
you need to call that method using object of the class.
replace
print_r($tweet_dbs)
with
print_r($tweet_dbs->index())
Upvotes: 0
Reputation: 4686
include('feeds.php');
$tweet_dbs = new updateFeed;
$tweets = $tweet_dbs->index();
print_r($tweets);
You missed to call the index() function..
Upvotes: 0
Reputation: 5512
You are using your class wrong. You do not call index() method. Try this:
include('feeds.php');
// Create class instance
$instance = new updateFeed;
// Call your class instance's method
$tweet_dbs = $instance->index();
// Check result and have fun
print_r($tweet_dbs);
Upvotes: 2