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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Getting table data for virtual page


Go to End


2 Posts   1228 Views

Avatar
goosejan

Community Member, 1 Post

30 July 2010 at 6:11am

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

Forum Moderator, 5523 Posts

30 July 2010 at 3:36pm

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