Skip to content

Instantly share code, notes, and snippets.

@jrast
Created July 13, 2012 17:59
Show Gist options
  • Save jrast/3106331 to your computer and use it in GitHub Desktop.
Save jrast/3106331 to your computer and use it in GitHub Desktop.
Tutorial: Suche für eigene DataObjects
<?php
class MyObject extends DataObject {
static $db = array(
'Title' => 'Varchar(255)',
'Content' => 'HTMLText'
);
}
<?php
class MyObject extends DataObject {
// ...
static $create_table_options = array('MySQLDatabase' => 'ENGINE=MyISAM');
public static $indexes = array(
"fulltext (Title, Content)"
);
}
<?php
class Page extends SiteTree {
// ...
}
class Page_Controller extends ContentController {
// ...
}
<?php
class Page extends SiteTree {
// ...
}
class Page_Controller extends ContentController {
// ...
public function results($data, $form){
$results = $form->getResults();
$query = htmlspecialchars($data['Search'], ENT_QUOTES,'UTF-8');
$objects = MyObject::get()->where("MATCH (Title, Content) AGAINST ('$query' IN BOOLEAN MODE)");
$results->merge($objects);
$data['Results'] = $results;
$data['Title'] = _t('SearchForm.SearchResults', 'Search Results');
$data['Query'] = $query;
return $this->customise($data)->renderWith(array('Page_results','Page'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment