2012-10-23 2 views
0

개체를 인스턴스화 할 위치로 배열을 반환해야하는 PHP 클래스가 있습니다. 나는 문제가 무엇인지 알아 내려고 노력했지만 그것을 볼 수는 없다. 내가 잘못 본 곳이나 올바른 방향으로 나를 가리키는 사람은 누구입니까? (. 'feeds.php라는 파일 내에서) 덕분에 여기 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; 

    } 

하는 클래스입니다 그리고 여기 객체가 인스턴스화되는 위치합니다 (index.php 파일에)입니다 :

include('feeds.php'); 
$tweet_dbs = new updateFeed; 
print_r($tweet_dbs); 

인덱스 파일의 print_r에 'updateFeed Object()'가 표시됩니다. 미리 감사드립니다.

+0

print_r($tweet_dbs) 

교체'인 print_r ($ tweet_dbs-> 지수());'당신은 클래스 메소드를 호출 적이있다. – insertusernamehere

답변

2

클래스를 잘못 사용하고 있습니다. 당신은 index() 메소드를 호출하지 않는다. 이 시도 : 당신은 인덱스() 함수를 호출 놓친

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); 
+0

Brilliant. 나는 그것이 어리석은 것을 알았다. 고맙습니다. – devoncrazylegs

0
include('feeds.php'); 
$tweet_dbs = new updateFeed; 
$tweets = $tweet_dbs->index(); 
print_r($tweets); 

..

0

을 당신은 클래스의 객체를 사용하여 해당 메소드를 호출 할 필요가있다.

그것은 간단해야한다

print_r($tweet_dbs->index()) 
+1

당신은 그 반대일까요? :) – insertusernamehere

+0

@insertusernamehere : 나는 당신을 얻지 못한다. –

+0

당신이 실제로 말하고 싶은 것은 "print_r ($ tweet_dbs)'*를 * print_r ($ tweet_dbs-> index())'"로 대체하십시오. – insertusernamehere

관련 문제