Version: current

     1 <?php
     2 /**
     3  * Extension to provide a search interface when applied to ContentController
     4  *
     5  * @package sapphire
     6  * @subpackage search
     7  */
     8 class ContentControllerSearchExtension extends Extension {
     9     static $allowed_actions = array(
    10         'SearchForm',
    11         'results',
    12     );
    13
    14     /**
    15      * Site search form
    16      */
    17     function SearchForm() {
    18         $searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
    19         $fields = new FieldSet(
    20             new TextField('Search', '', $searchText)
    21         );
    22         $actions = new FieldSet(
    23             new FormAction('results', 'Search')
    24         );
    25         return new SearchForm($this->owner, 'SearchForm', $fields, $actions);
    26     }
    27
    28     /**
    29      * Process and render search results.
    30      *
    31      * @param array $data The raw request data submitted by user
    32      * @param SearchForm $form The form instance that was submitted
    33      * @param SS_HTTPRequest $request Request generated for this action
    34      */
    35     function results($data, $form, $request) {
    36         $data = array(
    37             'Results' => $form->getResults(),
    38             'Query' => $form->getSearchQuery(),
    39             'Title' => 'Search Results'
    40         );
    41         return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));
    42     }
    43 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -