21278 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 299 Views |
-
Displaying Member profiles

4 January 2013 at 4:26am Last edited: 4 January 2013 4:44am
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 helpthis is the function I use to display them
for the picturefunction getPicture(){
$avatar = File::get()->innerJoin("Member", "\"Rel\".\"ImageID\" = \"File\".\"ID\"", "REl");
return $avatar;
}
for the Members detailfunction 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
-
Re: Displaying Member profiles

4 January 2013 at 6:10am Last edited: 4 January 2013 8:13am
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 %> -
Re: Displaying Member profiles

4 January 2013 at 7:30am Last edited: 4 January 2013 7:31am
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 -
Re: Displaying Member profiles

4 January 2013 at 8:15am Last edited: 4 January 2013 8:15am
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.
-
Re: Displaying Member profiles

4 January 2013 at 4:36pm Last edited: 4 January 2013 5:16pm
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 thisDataList::Create("Group")->relation("Members")
-
Re: Displaying Member profiles

5 January 2013 at 2:25am
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();
| 299 Views | ||
|
Page:
1
|
Go to Top |


