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.

Archive /

Our old forums are still available as a read-only archive.

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

Adding search 2.2.2


Go to End


5 Posts   2731 Views

Avatar
DHN

Community Member, 23 Posts

26 June 2008 at 2:52am

Hi Everyone...

Tried adding search using the tutorial thats in the wiki, but I can't get it to work will somebody please tell me where to put in the code in page.php. This is how it looks at the moment.

<?php

class Page extends SiteTree {
	static $db = array(
   'Date' => 'Date',
   'Author' => 'Text'
);
	static $has_one = array(
   );
   function getCMSFields() {
   $fields = parent::getCMSFields();
 
   $fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
   $fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');
    	
   return $fields;
   
}
}
class Page_Controller extends ContentController {
	function init() {
		parent::init();
		
		Requirements::themedCSS("layout");
		Requirements::themedCSS("typography");
		Requirements::themedCSS("form");
	}
}

?>

Avatar
Willr

Forum Moderator, 5523 Posts

26 June 2008 at 2:17pm

as it should be mentioned in the tutorial but you need to add it in the Controller part as this is the class that interacts with the templates (and you need to be able to call search from the templates)

class Page_Controller extends ContentController {
   function init() {
      parent::init();
      
      Requirements::themedCSS("layout");
      Requirements::themedCSS("typography");
      Requirements::themedCSS("form");
   }
   /* Add your 2 search methods here */
} 

Avatar
DHN

Community Member, 23 Posts

28 June 2008 at 8:08pm

this is so wierd.... I did what you said, and even tried on a completely new install and still i get an error saying:

Parse error: syntax error, unexpected T_VARIABLE in /home/www/mywww/mysite/code/Page.php on line 25

I have tried what I think is all possible solutions but it just won't work......

Avatar
Willr

Forum Moderator, 5523 Posts

28 June 2008 at 8:14pm

Parse error: syntax error, unexpected T_VARIABLE in /home/www/mywww/mysite/code/Page.php on line 25

Whats on line 25? Just probably a typo

Avatar
DHN

Community Member, 23 Posts

28 June 2008 at 8:19pm

This is exactly how page.php looks when i get the error

<?php

class Page extends SiteTree {
	static $db = array(
	);
	static $has_one = array(
   );
}

class Page_Controller extends ContentController {
	function init() {
		parent::init();
		
		Requirements::themedCSS("layout");
		Requirements::themedCSS("typography");
		Requirements::themedCSS("form");
	}
	function SearchForm() {
      $searchText = isset($this->Query) ? $this->Query : 'Search';
		
      $fields = new FieldSet(
         new TextField("Search", "", $searchText)
      );
 
      $actions = new FieldSet(
         new FormAction('results', 'Go')
      );
 
      return new SearchForm($this, "SearchForm", $fields, $actions);
   }
}

?>