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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Get Description of File to Show in Search Results


Go to End


4 Posts   1504 Views

Avatar
DeklinKelly

Community Member, 197 Posts

13 August 2010 at 12:35am

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?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

13 August 2010 at 1:20am

What search results are you talking about?

Avatar
DeklinKelly

Community Member, 197 Posts

13 August 2010 at 2:03am

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.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

13 August 2010 at 3:04am

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