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

Displaying Member profiles


7 Posts   741 Views


4 January 2013 at 4:26am (Last edited: 4 January 2013 4:44am), Community Member, 8 Posts

I'm trying to get my registered Members from the database and display them in the frontend.
I extended it using this class


class MyMember extends DataExtension {
   static $db = array(
      'Description' => 'Varchar(250)'
   static $has_one = array(   
      'Image' => 'Image'

public function getCMSFields() {

    $this->extend('updateCMSFields', $fields);
    return $fields;

   public function updateCMSFields(FieldList $fields) {

      $fields->push($imageUpload = new UploadField('Image', 'Profile Image'));
      return $fields;

So now my Members have a profile picture and a Description.
I am able to display the Members details and the image but SEPARATELY
because I don't really know how.
I'm not very familiar with Silverstripe and PHP
please help

this is the function I use to display them
for the picture

   function getPicture(){
      $avatar = File::get()->innerJoin("Member", "\"Rel\".\"ImageID\" = \"File\".\"ID\"", "REl");
      return $avatar;

for the Members detail

   function pullMembers(){
      $members = DataObject::get('Member');
      //$avatar = DataObject::get_by_id('Image', $members->ImageID);
      //return $members;
      return $members;

the templat

<div class="content-container">   
      <div class="content">
         <% control getPicture %>    
            <img style="width: 50px" src="$filename"/>
         <% end_control %>
         <% control pullMembers %>
         <% end_control %>
<% include SideBar %>

I would like to display their image together with the Members detail


4 January 2013 at 6:10am (Last edited: 4 January 2013 8:13am), Community Member, 189 Posts

Hi DairyPrincess

Thanks to SilverStripe, there's no need to setup a custom function to retrieve the picture. You'll also want to use DataList instead of DataObject::get() if this is a SS v3.0 project.

your new function to get members

public function getMembers(){
//make sure members exist.
if(DataList::create('Member')->count() >= 1){
return DataList::create('Member');

and in your template you should use <% loop %> not <% control %> permitting this is a v3.0 project. as an example

<% if $Members %>
<% loop $Members %>
<% end_loop %>
<% loop $Members %>
<% end_loop %>
<% end_if %>


4 January 2013 at 7:30am (Last edited: 4 January 2013 7:31am), Community Member, 8 Posts

thanks for the reply!
I tried your code but I'm getting a server error
I am using the 3.0.3 version
somehow I'm not getting errors about deprecated classes
not sure why haha
I just find out that something's wrong when I get a server error


4 January 2013 at 8:15am (Last edited: 4 January 2013 8:15am), Community Member, 189 Posts

There was a typo in my code (fixed now) i had DataList::create('Members'), when it should probably be DataList::create('Member');

if you still get errors after making that change let me know what they are.


4 January 2013 at 4:36pm (Last edited: 4 January 2013 5:16pm), Community Member, 8 Posts

Thank you!
It works now :D

I'm sorry but how do I display the members that belong to a specific group?
ex: all of the members that belong to Administrators
how do I use this



5 January 2013 at 2:25am Community Member, 189 Posts

If you want to display members from a certain group, I use something like

$group = DataList::create('Group')->byID('x') //x is the ID of the group you want
return $group->Members();

or you could use something like

$group = DataList::create("Group")->where("Title = 'Administrators'")->first();
return $group->Members();


5 January 2013 at 4:53am Community Member, 8 Posts

works great! thanks so much :D