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

Showing List of Members On A Page


Reply


3 Posts   818 Views

Avatar
TerryMiddleton

Community Member, 108 Posts

11 May 2009 at 8:15am

I need to show the list of members in a group to approve based on a field in members

So, I created a MembersToApprovePage.php and extended Page with also a page controller.

- MembersToApprovePage.php
<?php
/**
* Defines the MembersToApprovePage page type
*/
class MembersToApprovePage extends Page {
   static $db = array (
   );
   static $has_one = array (
   );
   static $allowed_children = array('MembersToApprovePage');
}
class MembersToApprovePage_Controller extends Page_Controller {

function MembersNeedingApproval($num=10) {
      $membersta = DataObject::get_one("MembersToApprovePage");
      return ($membersta) ? DataObject::get("MembersToApprovePage", "ParentID = $membersta->ID", "DESC", "", $num) : false;
}
}
?>

The Page shows up in the CMS fine when I create a page and select a page type, but it doesn't render and I get an error.

Does anyone know of a good tutorial that explains querying a table and showing the list on a page? I tried to emulate Tutorial-2 extending a basic site, but apparently not well enough.

Terry

Avatar
david_nash

Community Member, 55 Posts

11 May 2009 at 11:46am

Hi Terry

What's the error that you get? Is it only failing when you call MembersNeedingApproval() from the template?

I think maybe your problem is get_one() - if you want multiple objects you'll need to use get() instead.

http://api.silverstripe.com/sapphire/core/DataObject.html#get

cheers,
David

Avatar
Willr

Forum Moderator, 5513 Posts

11 May 2009 at 12:01pm

You might need to quote the ID in the DataObject get

return ($membersta) ? DataObject::get("MembersToApprovePage", "ParentID = '$membersta->ID'", "DESC", "", $num) : false;