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

is the search TUTORIAL correct?


Reply

3 Posts   428 Views

Avatar
Richi

9 November 2011 at 5:18am (Last edited: 9 November 2011 5:19am), Community Member, 16 Posts

Hey there,
the search tutorial seems to be simple, but I must be missing out something.
I'm asking because I keep getting a fatal error when I try to open e.g. mydomain.com/home/results and the search itself does not work at all.

I did all what the tutorial told me to do, function results in page.php, created the Page_results.ss and FulltextSearchable::enable(); in my config.

Fatal error: Call to a member function getResults() on a non-object in .../mysite/code/Page.php on line 22

Page.php

<?php
class Page extends SiteTree {

   public static $db = array(
    'Sidecontent' => 'HTMLText'
   );

   public static $has_one = array(
   );
   
   function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Sidecontent", new HTMLEditorField('Sidecontent','Sidecontent Content'));
return $fields;
}

}
class Page_Controller extends ContentController {
   
   function results($data, $form){
$data = array(
'Results' => $form->getResults(),
'Query' => $form->getSearchQuery(),
'Title' => 'Search Results'
);
$this->Query = $form->getSearchQuery();

return $this->customise($data)->renderWith(array('Page_results', 'Page'));
}

   /**
    * An array of actions that can be accessed via a request. Each array element should be an action name, and the
    * permissions or conditions required to allow the user to access it.
    *
    * <code>
    * array (
    * 'action', // anyone can access this action
    * 'action' => true, // same as above
    * 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
    * 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
    * );
    * </code>
    *
    * @var array
    */
   
   public static $allowed_actions = array (
   );

   public function init() {
      parent::init();

      // Note: you should use SS template require tags inside your templates
      // instead of putting Requirements calls here. However these are
      // included so that our older themes still work
      Requirements::themedCSS('layout');
      Requirements::themedCSS('typography');
      Requirements::themedCSS('form');
   }
}

Would be nice if someone could help me out here. Thank you!

Avatar
Willr

10 November 2011 at 9:02pm Forum Moderator, 5511 Posts

If you have SS2.4 then you don't need the tutorial - it's built in http://doc.silverstripe.org/sapphire/en/tutorials/4-site-search#2-4-and-newer

Avatar
Richi

10 November 2011 at 9:19pm Community Member, 16 Posts

Yes, I do use SS 2.4.
Do you mean, I don't have to build the Page_results.ss, nor do I have to alter my page.php, if I use 2.4?
Testing this right now, this wasnt clear to me.

Thank you Willr!