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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

is the search TUTORIAL correct?


Go to End


3 Posts   855 Views

Avatar
Richi

Community Member, 16 Posts

9 November 2011 at 5:18am

Edited: 09/11/2011 5:19am

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

Forum Moderator, 5523 Posts

10 November 2011 at 9:02pm

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

Community Member, 16 Posts

10 November 2011 at 9:19pm

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!