Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

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

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

Adding search 2.2.2


Reply

5 Posts   1855 Views

Avatar
DHN

26 June 2008 at 2:52am Community Member, 23 Posts

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");
   }
}

?>

Avatar
Willr

26 June 2008 at 2:17pm Forum Moderator, 5511 Posts

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 */
}

Avatar
DHN

28 June 2008 at 8:08pm Community Member, 23 Posts

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

Avatar
Willr

28 June 2008 at 8:14pm Forum Moderator, 5511 Posts

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

Avatar
DHN

28 June 2008 at 8:19pm Community Member, 23 Posts

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);
}
}

?>