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

Data Model Questions /

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

How to get an array containing only data from one column

Go to End

2 Posts   3395 Views


Community Member, 31 Posts

29 April 2014 at 7:03am

I've been going over tons of posts and the data model documentation. Maybe I am just blind for the obvious by now but I only find options, that retrieve ALL columns from data objects (which would equal SELECT * in SQL). What I need is to get only the data from one specific column that matches the criteria (SELECT Filename FROM ... WHERE ParentID=85). Neither the filter nor sort options will provide this as far as I can tell. Here is my set-up:

I have a list of images saved to a specific folder with a fixed ID. I need to pass the "Filenames" dynamically as an array to a customScript in the init(); within the Page_Controller. If I would need to access this on the template, I'd do:

function GetImages(){
	return DataObject::get("Image", "ParentID = 85");

and call the method in the template but limit it to the wanted data:

<% control GetImages %>
<% end_control %>

How do I get only the data from the column "Filename" into an array, that I then can use in my customScript also within the init() of the controller:

"file1.jpg", "file2.jpg", "file3.jpg" //THIS IS WERE THE ARRAY WOULD GO
], {
fade: 750,
duration: 4000

Thankful for any hint!