Jump to:

23376 Posts in 18229 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Getting table data for virtual page

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: 915 Views
  • goosejan
    Avatar
    Community Member
    1 Post

    Getting table data for virtual page Link to this post

    Hi guys,

    although i read the tutorials i guess i missed something.

    I'm trying to show data from a database table on a page.

    I've defined a Holder "ListingHolder" and a Page "ListingPage".

    The ListingPage defines a table via static $db, nothing complex, just some fields.

    The ListingPage controller has a method named ShowAllEntries.

    In there i call DataObject::get('ListingPage') and expect to get all entries from the table ListingPage_Live.

    Sadly, I only get the first row.

    I've digged a bit deeper and found the reason for this:

    The SQL Query generated fetches only Pages that have an entry in SiteTree_Live.

    To summarize what I want to achieve:

    When the Page "ListingPage" is called in the Browser, Silverstripe should generate a List of all entries in a table (atm ListingPage_Live), regardless if they belong to a page.

    Why? I want to fill the table from an external data source, so I don't need a page per entry plus the amount of data is huge, so it would probably slow down the admin interface a lot.

    Could you please give me a hint how to dump out the table data?

    Thanks in advance, goosejan

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Getting table data for virtual page Link to this post

    Why? I want to fill the table from an external data source, so I don't need a page per entry plus the amount of data is huge, so it would probably slow down the admin interface a lot.

    If you are dealing with data pulled from a thirdparty and they don't need to be pages then you may want to use dataobjects instead of pages. Then you won't run into Live, Staging issues. If you want to proceed with keeping them page objects (which by the sounds of it you don't need to) then instead of DataObject::get() you can use Versioned::get_by_stage() to specifically get from the draft stage.

    http://api.silverstripe.org/2.4/sapphire/model/Versioned.html#methodget_by_stage

    915 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.