How to transfer user data to a template

I am new to OOP in general and Silverstripe in particular. I am sure that I am missing something vital!

I'm currently trying to create a Twitter feed for my homepage. In my Page_controller, I have:

public function getTwitterFeed() { ... }

... which receives a set of tweets. I can format this data as I like, so the data structure and function should be out of date.

In Silverstripe tutorials, they give the following example:

public function LatestNews($num=5) {
    $holder = NewsHolder::get()->First();
    return ($holder) ? News::get()->filter('ParentID', $holder->ID)->sort('Created', 'DESC')->limit($num) : false;
}

Then it is called in the template as follows:

<% loop LatestNews %>
    <% include NewsTeaser %>
<% end_loop %>

However, this function is based on the DataModel (NewsHolder) object and receives data from the database (which my twitter function does not work).

So what type of variable should this function return? An array? An object?

+5
source share
1

SilverStripe 3.0 2 , <% loop %> <% with %>

  • <% loop %> , SS_List (: DataList, ArrayList)
  • <% with %> , ViewAbleData, (: DataObject, ArrayData,...)

( SilverStripe 2.x <% control %>, )

, <% loop TwitterFeed %>? ArrayList

( , ):

    public function getTwitterFeed() {
            return new ArrayList(array(
                    new ArrayData(array(
                            'Name' => 'Zauberfisch',
                            'Message' => 'blubb',
                    )),
                    new ArrayData(array(
                            'Name' => 'Foo',
                            'Message' => 'ohai',
                    )),
                    new ArrayData(array(
                            'Name' => 'Bar',
                            'Message' => 'yay',
                    ))
            ));
    }


    <% loop TwitterFeed %>
            $Name wrote: $Message<br />
    <% end_loop %>

, twitter ArrayData, ArrayList ( 1 ArrayData)

+16

All Articles