Jump to:

23553 Posts in 19380 Topics by 2892 members

General Questions

SilverStripe Forums » General Questions » Member based $searchable_fields

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: 1144 Views
  • micahsheets
    Avatar
    Community Member
    164 Posts

    Member based $searchable_fields Link to this post

    I have been told that to make $searchable_fields based on members group or permissions I have to use a public function searchableFields() instead of a static $searchable_fields. However I cannot figure out the syntax.

    I need one set of searchable fields for one user group and another set for another user group for the same DataObject.

    I figured it would be:

    public function searchableFields() {

    $member = Member::currentUser();

    $searchable_fields = array(
          'BestNotesID',
          'FirstName',
          'Surname',
          'Therapist.FirstName',
          'StudentGroup.Name'
       );

    if ($member && $member->inGroups(array('office-staff', 'office-managers'))) {
    $searchable_fields[] = 'OfficeLocation';
    {

    return $searchable_fields;
    }

    This code throws the error: Fatal error: Class 'B' not found in ....... sapphire/core/model/DataObject.php on line 1632

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Member based $searchable_fields Link to this post

    If you define a searchableFields() method you need to to a bit of pre-processing yourself. Try returning this instead, as an example.

    $searchable_fields = array(
    'BestNotesID' => array(),
    'FirstName' => array('title' => 'First name'),
    'Surname' => array(),
    'Therapist.FirstName' => array(),
    'StudentGroup.Name => array()'
    );

  • micahsheets
    Avatar
    Community Member
    164 Posts

    Re: Member based $searchable_fields Link to this post

    Thanks for the help, I got it working. Now I need to make one of the search fields a dropdown instead of a text field. Is there a way to do this? The dropdown would be populated with the names of DataObjects of a particular class.

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