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.

Data Model Questions

List images from upload directory


12 Posts   4664 Views


14 April 2013 at 8:51am (Last edited: 14 April 2013 9:13am), Community Member, 80 Posts

if your foldername is hardcodet anyway you can do this:

function RotateImages(){
return DataObject::get("Image", "ParentID = '123'");

just look up the ID of your Folder in the File Table and replace the 123...


14 April 2013 at 9:41am (Last edited: 14 April 2013 9:42am), Community Member, 11 Posts

Sweet >> ok - that worked.

I have two templates. One for the home page and then another for the sub pages and was planning to use the DropdownTree field on the sub page template. The reason is that I will have a different set of photos for each sub page. When I updated my php page with the following code, I seemed to have caused some issues. Now in the CMS, the sub page template doesn't load, the screen is just white.

I have multiple sites running and I am using symbolic links. None of the other sites are impacted by this yet I get an error that points to line 295 in the framework. I only see the error if I set Director::set_environment_type("dev"); in the config. Line 295 in /home/[USER ACCOUNT]/SSLive3/framework/forms/FieldList.php . " '{$parentPointer->class}'{$withName} - '$part' didn't exist.", E_USER_ERROR);

Some forum pages have suggested removing the _combinedfiles or setting it to false in the config page and that hasn't worked.

$fields->addFieldToTab('Root.Main', new TreeDropdownField('FolderID', 'Choose Image Folder', 'Folder'), 'Main');

static $has_one = array (
'Folder' => 'Folder'


14 April 2013 at 8:55pm (Last edited: 14 April 2013 8:55pm), Community Member, 80 Posts

I don't exactly understand your symbolic link thing. Here you just get the code that worked for me (I just tested it in a clean Silverstripe 3.0.5 installation):
For your SubPage Class:

static $has_one = array(
'MyImagesFolder' => 'Folder'

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new TreeDropdownField('MyImagesFolderID', 'MyImagesFolder', 'Folder'), 'Content');
return $fields;

function RotateImages(){
return DataObject::get("Image", "ParentID = '{$this->MyImagesFolderID}'");

SubPage Template:

<% loop RotateImages %>
<% end_loop %>

run dev/build afterwards and then it has to work. Otherwise your problem indeed is located somewhere else.


15 April 2013 at 2:11am Community Member, 11 Posts

Thank you for your help - I really appreciate it.

The comment about the symbolic links is that many sites share the same SS code base. As such, a framework error should then occur on all sites. It did not so the error must be isolated and related to something in mysite php files.

To prove this, I commented out the fields I had added to my custompage.php file and the error message for line 295 went away.

I had upgraded the site from v2.5.x to SS3 a few months ago and thought I had updated the syntax correctly for adding my custom fields to the custompage.php. That is removing Content from the code. But I missed 1 main part and it was causing the issue.

$fields->addFieldToTab('Root.Content.Main.Featured', new HTMLEditorField('HP_FP_theme', 'Theme'));

v3.x - my error >> I removed Content for SS3 but I did not remove Main when adding a new tab called Featured.
$fields->addFieldToTab('Root.Main.Featured', new HTMLEditorField('HP_FP_theme', 'Theme'));

Realizing this, I changed the code to:
$fields->addFieldToTab('Root.Featured', new HTMLEditorField('HP_FP_theme', 'Theme'));

and the error for line 295 goes away. I also added the dropdown for the folder ID and it works perfectly.

Thank you! This issue is solved.