Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## mysite/code/Equipment.php
- <?php
- class Equipment extends Page {
- function getCMSFields() {
- return parent::getCMSFields(Array(
- 'includeRelations' => true,
- ));
- }
- static $has_many = Array(
- 'Features' => 'Equipment_Feature',
- 'Options' => 'Equipment_Option'
- );
- }
- class Equipment_Attribute extends DataObject {
- static $db = Array(
- 'AttrTitle' => 'HTMLVarchar',
- 'AttrDesc' => 'HTMLText'
- );
- static $has_one = Array(
- 'Parent' => 'Equipment'
- );
- }
- class Equipment_Feature extends Equipment_Attribute {
- }
- class Equipment_Option extends Equipment_Attribute {
- }
- Class Equipment_Controller extends Page_Controller {
- public function init() {
- parent::init();
- }
- }
- ?>
- ## mysite/code/Page.php
- <?php
- class Page extends SiteTree {
- function getCMSFields() {
- return parent::getCMSFields(Array(
- 'includeRelations' => true,
- ));
- }
- public static $db = array(
- );
- public static $has_one = array(
- );
- }
- class Page_Controller extends ContentController {
- /**
- * Grand Child Function (to pull content from grandchild (ie Equipment > Storage > Features(Content))
- */
- function getChildByTitle($theTitle) {
- $child = false;
- if (($this->dataRecord->ID) && ($this->dataRecord->ID != 0)) {
- $child = DataObject::get_one('SiteTree',"`Title` = '".Convert::raw2sql($theTitle)."' and `ParentID` = ".$this->dataRecord->ID);
- }
- return $child;
- }
- function getGrandChildrenOf($theTitle) {
- $results = false;
- if (($this->dataRecord->ID) && ($this->dataRecord->ID != 0)) {
- $child = DataObject::get_one('SiteTree',"`Title` = '".Convert::raw2sql($theTitle)."' and `ParentID` = ".$this->dataRecord->ID);
- if ($child) {
- $children = DataObject::get('SiteTree','`ParentID` = '.$child->ID);
- $results = $children;
- }
- }
- return $results;
- }
- public function init() {
- parent::init();
- // Note: you should use SS template require tags inside your templates
- // instead of putting Requirements calls here. However these are
- // included so that our older themes still work
- // Requirements::themedCSS("layout");
- // Requirements::themedCSS("typography");
- // Requirements::themedCSS("form");
- }
- /**
- * Site search form
- */
- function SearchForm() {
- $searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
- $fields = new FieldSet(
- new TextField("Search", "", $searchText)
- );
- $actions = new FieldSet(
- new FormAction('results', 'Search')
- );
- return new SearchForm($this, "SearchForm", $fields, $actions);
- }
- /**
- * Process and render search results
- */
- function results($data, $form){
- $data = array(
- 'Results' => $form->getResults(),
- 'Query' => $form->getSearchQuery(),
- 'Title' => 'Search Results'
- );
- return $this->customise($data)->renderWith(array('Page_results', 'Page'));
- }
- }
- ?>
- ## end
Add Comment
Please, Sign In to add comment