Jump to:

23491 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Saving images in members profil

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

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

Page: 1
Go to End
Author Topic: 353 Views
  • Bereusei
    Avatar
    Community Member
    94 Posts

    Saving images in members profil Link to this post

    Hey guys,

    I want to deposit images for members in the backend of SS3. Therefore I´ve tried to extend the member settings in "security".

    CustomMember.php:

    class CustomMember extends DataExtension{
       
    private static $many_many = array(
       'Images' => 'Image'
    );

    public function getCMSFields() {
          $this->extend('updateCMSFields', $fields);
          return $fields;
       }

    public function updateCMSFields(FieldList $fields) {
          $fields->push(new UploadField('Images', 'Profile Image'));
       }
    }


    This part of the code works fine. I can save images and documents under a name of the member.
    But know I´ve tried to list the images in frontend and get the error:
    [Error] Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'HasManyList'

    MembersPage.php:

    class MembersPage extends Page{
       
       public static $has_many = array(
          "CustomMembers" => "CustomMember"
       );
       
       function getMembers(){
          $MemberSet = DataObject::get('Member');
          return $MemberSet;
       }
       
    }

    MembersPage.ss

    <% control getMembers %>
       $Images
    <% end_control %>

    How can I display the images in the frontend?
    Thanks for help!

  • kinglozzer
    Avatar
    Community Member
    142 Posts

    Re: Saving images in members profil Link to this post

    Hi,

    You need to loop through the list of images in the same way you loop through members. In your template try:

    <% control getMembers %>
    <% control $Images %>
    $SetWidth(150)
    <% end_control %>
    <% end_control %>

  • Bereusei
    Avatar
    Community Member
    94 Posts

    Re: Saving images in members profil Link to this post

    This is it! Thanks!

    353 Views
Page: 1
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.