HelloBetterLTD/elemental-seach

I'm trying to follow your instructions but having issues

nimeso opened this issue · 3 comments

I'm just wanting a simple page search.

mysite.yml

SilverStripe\CMS\Model\SiteTree:
  extensions:
    - SilverStripers\ElementalSearch\Extensions\SearchDocumentGenerator

PageController.php

<?php

namespace {
    use SilverStripe\View\Requirements;
    use SilverStripe\CMS\Controllers\ContentController;
    use SilverStripe\CMS\Search\SearchForm;

    class PageController extends ContentController
    {
        /**
         * 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>
         * [
         *     '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
         */
        private static $allowed_actions = [
            "SearchForm",
            "results"
        ];

        protected function init()
            {
                parent::init();                
                Requirements::javascript('public/javascript/scripts.min.js');
                
            }

        public function SearchForm() 
        {
            return SearchForm::create($this, 'SearchForm');
        }
           
        public function results($data, $form, $request)
        {
            $data = array(
                'Results' => $form->getResults(),
                'Query' => DBField::create_field('Text', $form->getSearchQuery()),
                'Title' => _t('SilverStripe\\CMS\\Search\\SearchForm.SearchResults', 'Search Results')
            );
            return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));
        }
    }
}

In my Header.ss Includes I have $SearchForm
SearchForm show correctly but when it jumps to /home/SearchForm/?Search=test&action_results=Go

I get this error:
[Emergency] Uncaught Error: Class 'DBField' not found
Which seems to be coming from
'Query' => DBField::create_field('Text', $form->getSearchQuery()),

If I remove that line it works but no results are found.

This is driving me nuts lol. I just want a super simple search like SS3 lol.

Any help would be great and thanks for all the hard work.

You need to include SilverStripe\ORM\FieldType\DBField in your use statements

@nimeso Sorry about the late response on your question. Do you still have the problem? As @peterkoopman pointed out did you try including use SilverStripe\ORM\FieldType\DBField in use section?

Btw, Thank you very much @peterkoopman responding to the question.

I think I'm all good. Thank you soooo much. Keep rocking.