Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » List images from upload directory

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

Page: 1 2
Go to End
Author Topic: 4419 Views
  • spierala
    Avatar
    Community Member
    80 Posts

    Re: List images from upload directory Link to this post

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

  • acktivate
    Avatar
    Community Member
    11 Posts

    Re: List images from upload directory Link to this post

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

  • spierala
    Avatar
    Community Member
    80 Posts

    Re: List images from upload directory Link to this post

    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

  • acktivate
    Avatar
    Community Member
    11 Posts

    Re: List images from upload directory Link to this post

    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.

    4419 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.