1 <?php
2
3 class Search_Controller extends Page_Controller {
4
5 static $search_active = true;
6
7 function init() {
8 parent::init();
9
10 if (!self::$search_active) {
11 return $this->httpError(404);
12 }
13 }
14
15 function Link($action = null) {
16 return Controller::join_links(Director::baseURL(), 'search');
17 }
18
19 function SearchForm() {
20 $searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : '';
21 $fields = new FieldSet(
22 new TextField("Search", "", $searchText)
23 );
24 $actions = new FieldSet(
25 new FormAction('results', _t('Webylon.SEARCH', 'Search'))
26 );
27
28 return new SearchForm($this, "SearchForm", $fields, $actions);
29 }
30
31 32 33
34
35 function SearchActive() {
36 return isset($_REQUEST['Search']);
37 }
38
39 function results($d = array(), $form = false){
40 if (!$form)
41 return false;
42 $form->setPageLength(20);
43 $form->classesToSearch(array('SiteTree'));
44 $data = array(
45 'Results' => $form->getResults(),
46 'Query' => $form->getSearchQuery(),
47 'Title' => _t('Webylon.SEARCH_RESULTS','Search Results')
48 );
49
50 return $this->renderWith(array('Search', 'Page'),$data);
51 }
52
53 function Title() {
54 return _t('Webylon.SEARCH', 'Search');
55 }
56
57 function getClassName() {
58 return 'Search';
59 }
60 }
61
62
[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.
-