Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

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

Getting table data for virtual page


Reply

2 Posts   940 Views

Avatar
goosejan

30 July 2010 at 6:11am Community Member, 1 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 :)

Avatar
Willr

30 July 2010 at 3:36pm Forum Moderator, 5511 Posts

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