Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » Class ArrayList not found..

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 409 Views
  • borriej
    Avatar
    Community Member
    267 Posts

    Class ArrayList not found.. Link to this post

    Ok simple question, why do i get this error:

    Fatal error: Class 'ArrayList' not found in /public/sites/..../mysite/code/Tweet.php on line 68

    my code

    Tweet.php

    <?php

    /**
    * Loads tweets onto a SilverStripe object through a XML file rather than the
    * web API.
    *
    * Usage:
    *
    *    // PHP
    *   function Tweets() {
    *       return Tweet::get('http://twitter.com/statuses/user_timeline/willrossi.rss', 10);
    *    }   
    *
    *   // SS
    *   <% if $Tweets %>
    *      <% loop $Tweets %>
    *         $Description on $PubDate.Nice
    *      <% end_loop %>
    *   <% end_if %>
    *
    * @license http://sam.zoy.org/wtfpl/COPYING
    * @author Will Rossiter (will@fullscreen.io)
    */

    class Tweet extends ViewableData {

       protected $description;
       protected $pubDate;

       public function __construct($description, $pubDate) {
          $this->description = $description;
          $this->pubDate = $pubDate;
       }

       /**
        * Parses hash tags, @usernames, and URLs in a tweet description into
        * HTML links.
        *
        * @return string
        */
       public function getDescription() {
          $desc = $this->description;

          $desc = substr(strstr($desc, ': '), 2, strlen($desc)); // remove preceding username
          $desc = preg_replace("/(http:\/\/)(.*?)\/([\w\.\/\&\=\?\-\,\:\;\#\_\~\%\+]*)/", "<a href=\"\\0\">\\0</a>", $desc); // URLs into links
          $desc = preg_replace('/(^|\s)#(\w+)/', '\1<a href="http://search.twitter.com/search?q=%23\2">#\2</a>', $desc); // Hash tags to links

          return DBField::create_field('HTMLText', $desc);
       }

       /**
        * @return SS_Datetime
        */
       public function getPubDate() {
          return DBField::create_field('SSDatetime', $this->pubDate);
       }

       /**
        * Get some tweets from static file with a limit.
        *
        * @param int $limit Limit number of tweets
        * @return ArrayList
        */
       public static function get($path, $limit) {
          $cache = SS_Cache::factory('tweets');

          if (!($output = unserialize($cache->load('tweets')))) {
             $output = new ArrayList();
             $context = stream_context_create(array(
                'http' => array(
                   'method' => 'GET',
                   'timeout' => 5
                )
             ));

             $tweets = @file_get_contents($path, '', $context);
             if(!$tweets) return false;
             
             $xml = new SimpleXMLElement($tweets);
             $total = 0;

             foreach($xml->xpath('channel/item') as $item) {
                $output->push(new Tweet(
                   (string) $item->description,
                   (string) $item->pubDate
                ));

                $total++;

                if($total == $limit) break;
             }

             $cache->save(serialize($output));
          }

          return $output;
       }
    }

    and inside homepage.php

    class Homepage_Controller extends Page_Controller {
          
       function Tweets() {
          return Tweet::get('http://twitter.com/statuses/user_timeline/myusername.rss', 5);
       }   

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Class ArrayList not found.. Link to this post

    FYI that code was written for 3.0. You should have a framework/model/ArrayList.php file with the class in it.

    409 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.