Jump to:

1999 Posts in 1421 Topics by 613 members

Form Questions

SilverStripe Forums » Form Questions » Understanding the SearchForm Method

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

Page: 1
Go to End
Author Topic: 1977 Views
  • J2-Paul
    Avatar
    Community Member
    51 Posts

    Understanding the SearchForm Method Link to this post

    Can someone please explain how to extend the SearchForm class.

    My aim is to modify the default text and button text initially, but will probably extend to more changes later.

    I have located the function in this file " \saphire\search\ContentControllerExtension.php"

    The easy thing to do would be to make the changes in this file. But messing with the core files is not ideal of course.

    I have tried extending the Searchform.php class as follows:

    Create new class "SiteSearch.php" in mycode

    class SiteSearch extends SearchForm {

          function __construct($controller,$name){

             parent::__construct($controller,$name);
       
       }

    }

    Putting $SiteSearch in my template and I get the default form rendering OK. But I get the error below.

    Any help would be much appreciated.

    [User Error] Uncaught Exception: Object->__call(): the method 'getviewer' does not exist on 'DataObjectSet'
    GET /home/SiteSearch?Search=&action_getResults=Go

    Line 724 in E:\websites\IRIS\v2\sapphire\core\Object.php
    Source

    715             
    716             default :
    717                throw new Exception (
    718                   "Object->__call(): extra method $method is invalid on $this->class:" . var_export($config, true)
    719                );
    720          }
    721       } else {
    722          // Please do not change the exception code number below.
    723          
    724          throw new Exception("Object->__call(): the method '$method' does not exist on '$this->class'", 2175);
    725       }
    726    }
    727    
    728    // -----------------------------------------------------------------------------------------------------------------
    729    
    730    /**

    Trace

    * Object->__call(getViewer,Array)
    * DataObjectSet->getViewer(SiteSearch)
    Line 155 of Controller.php
    * Controller->handleRequest(SS_HTTPRequest)
    Line 199 of ContentController.php
    * ContentController->handleRequest(SS_HTTPRequest)
    Line 67 of ModelAsController.php
    * ModelAsController->handleRequest(SS_HTTPRequest)
    Line 283 of Director.php
    * Director::handleRequest(SS_HTTPRequest,Session)
    Line 127 of Director.php
    * Director::direct(home/SiteSearch)
    Line 127 of main.php

  • Willr
    Avatar
    Forum Moderator
    5483 Posts

    Re: Understanding the SearchForm Method Link to this post

    If you want to override the search form (well the button and the text copy the content from the ContentControlellerExtension class to your Page.php then you can customize it as much as you wish.

  • J2-Paul
    Avatar
    Community Member
    51 Posts

    Re: Understanding the SearchForm Method Link to this post

    Thanks Willr. I think the penny has dropped here! I am kicking myself right now!

    Much appreciated!

  • BlueO
    Avatar
    Community Member
    52 Posts

    Re: Understanding the SearchForm Method Link to this post

    Thank you for posting this! There are a lot of conflicting posts and this one finally answers how to customise the search form and button in 2.4

    b

  • Pinky
    Avatar
    Community Member
    2 Posts

    Re: Understanding the SearchForm Method Link to this post

    It is too good

  • Pinky
    Avatar
    Community Member
    2 Posts

    Re: Understanding the SearchForm Method Link to this post

    It is too good

    1977 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.