Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Adding search 2.2.2

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1825 Views
  • DHN
    Avatar
    Community Member
    23 Posts

    Adding search 2.2.2 Link to this post

    Hi Everyone...

    Tried adding search using the tutorial thats in the wiki, but I can't get it to work will somebody please tell me where to put in the code in page.php. This is how it looks at the moment.

    <?php

    class Page extends SiteTree {
       static $db = array(
    'Date' => 'Date',
    'Author' => 'Text'
    );
       static $has_one = array(
    );
    function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');
       
    return $fields;

    }
    }
    class Page_Controller extends ContentController {
       function init() {
          parent::init();
          
          Requirements::themedCSS("layout");
          Requirements::themedCSS("typography");
          Requirements::themedCSS("form");
       }
    }

    ?>

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Adding search 2.2.2 Link to this post

    as it should be mentioned in the tutorial but you need to add it in the Controller part as this is the class that interacts with the templates (and you need to be able to call search from the templates)

    class Page_Controller extends ContentController {
    function init() {
    parent::init();

    Requirements::themedCSS("layout");
    Requirements::themedCSS("typography");
    Requirements::themedCSS("form");
    }
    /* Add your 2 search methods here */
    }

  • DHN
    Avatar
    Community Member
    23 Posts

    Re: Adding search 2.2.2 Link to this post

    this is so wierd.... I did what you said, and even tried on a completely new install and still i get an error saying:

    Parse error: syntax error, unexpected T_VARIABLE in /home/www/mywww/mysite/code/Page.php on line 25

    I have tried what I think is all possible solutions but it just won't work......

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Adding search 2.2.2 Link to this post

    Parse error: syntax error, unexpected T_VARIABLE in /home/www/mywww/mysite/code/Page.php on line 25

    Whats on line 25? Just probably a typo

  • DHN
    Avatar
    Community Member
    23 Posts

    Re: Adding search 2.2.2 Link to this post

    This is exactly how page.php looks when i get the error

    <?php

    class Page extends SiteTree {
       static $db = array(
       );
       static $has_one = array(
    );
    }

    class Page_Controller extends ContentController {
       function init() {
          parent::init();
          
          Requirements::themedCSS("layout");
          Requirements::themedCSS("typography");
          Requirements::themedCSS("form");
       }
       function SearchForm() {
    $searchText = isset($this->Query) ? $this->Query : 'Search';
          
    $fields = new FieldSet(
    new TextField("Search", "", $searchText)
    );
     
    $actions = new FieldSet(
    new FormAction('results', 'Go')
    );
     
    return new SearchForm($this, "SearchForm", $fields, $actions);
    }
    }

    ?>

    1825 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.