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.

General Questions /

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

Saving images in members profil


Reply


3 Posts   389 Views

Avatar
Bereusei

Community Member, 94 Posts

5 June 2013 at 9:43pm

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!

Avatar
kinglozzer

Community Member, 167 Posts

5 June 2013 at 10:53pm

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

Avatar
Bereusei

Community Member, 94 Posts

6 June 2013 at 5:59pm

This is it! Thanks!