Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Get Description of File to Show in Search Results

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1076 Views
  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    Get Description of File to Show in Search Results Link to this post

    Out of the box, SilverStripe 2.4 with the Data Object Manager supports search results for files added with the data object manager.

    The template code below shows the name of the file being searched for but NOT the description:

    <h3><a class="searchResultHeader" href="$Link">$Title</a></h3>
    <p>$Description</p>

    Here is my PHP code:

    <?php

    class FileItem extends DataObject
    {
       static $db = array (
          'Text' => 'Varchar',
          'Description' => 'Text'
       );

       static $has_one = array(
          'Attachment' => 'File',
          'Page'=>'Page'

       );

       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Text','File Title'),
             new TextareaField('Description','Description for Search Results'),
             new FileIFrameField('Attachment','File')
          );
       }
    }

    ?>

    How can I get the Description to show in search results?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Get Description of File to Show in Search Results Link to this post

    What search results are you talking about?

  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    Re: Get Description of File to Show in Search Results Link to this post

    When I go here:

    /search-results/SearchForm?Search=foobar&action_results=Search

    Files with "foobar" in their filename are returned in the result list but I also want the Description.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Get Description of File to Show in Search Results Link to this post

    The Silverstripe search form searches SiteTree and File objects. It doesn't search on any other DataObject subclasses that you've defined.

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