Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Displaying Member profiles

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: 703 Views
  • DairyPrincess
    Avatar
    Community Member
    8 Posts

    Displaying Member profiles Link to this post

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

    <?php

    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'));
          
          $imageUpload->setFolderName('Profile');
          
          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">   
       <article>
          <h1>$Title</h1>
          <div class="content">
             $Content
             
             <% control getPicture %>    
             
                <img style="width: 50px" src="$filename"/>
             
             <% end_control %>
             
             <% control pullMembers %>
                <ul>   
                <li><p><b>$Title</b></p></li>
                <p>$Email</p>
                <p>$Description<p>
                </ul>
             <% end_control %>
             
          </div>
       </article>
          $Form
    </div>
    <% include SideBar %>

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

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Displaying Member profiles Link to this post

    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 %>
    $Image.setWidth(125)
    <% end_loop %>
    <ul>
    <% loop $Members %>
    <li>$Email</li>
    <li>$Description</li>
    <% end_loop %>
    </ul>
    <% end_if %>

  • DairyPrincess
    Avatar
    Community Member
    8 Posts

    Re: Displaying Member profiles Link to this post

    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

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Displaying Member profiles Link to this post

    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.

  • DairyPrincess
    Avatar
    Community Member
    8 Posts

    Re: Displaying Member profiles Link to this post

    Thank you!
    It works now

    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

    DataList::Create("Group")->relation("Members")

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Displaying Member profiles Link to this post

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

  • DairyPrincess
    Avatar
    Community Member
    8 Posts

    Re: Displaying Member profiles Link to this post

    works great! thanks so much

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