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.

Data Model Questions /

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

List images from upload directory


Go to End


12 Posts   12158 Views

Avatar
spierala

Community Member, 80 Posts

14 April 2013 at 8:51am

Edited: 14/04/2013 9:13am

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

Avatar
acktivate

Community Member, 11 Posts

14 April 2013 at 9:41am

Edited: 14/04/2013 9:42am

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'
);

Avatar
spierala

Community Member, 80 Posts

14 April 2013 at 8:55pm

Edited: 14/04/2013 8:55pm

HI,
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 %>
    $Tag
<% end_loop %>

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

Avatar
acktivate

Community Member, 11 Posts

15 April 2013 at 2:11am

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.

v2.5.x
$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.

Go to Top