Created
July 13, 2012 17:59
-
-
Save jrast/3106331 to your computer and use it in GitHub Desktop.
Tutorial: Suche für eigene DataObjects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyObject extends DataObject { | |
static $db = array( | |
'Title' => 'Varchar(255)', | |
'Content' => 'HTMLText' | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyObject extends DataObject { | |
// ... | |
static $create_table_options = array('MySQLDatabase' => 'ENGINE=MyISAM'); | |
public static $indexes = array( | |
"fulltext (Title, Content)" | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Page extends SiteTree { | |
// ... | |
} | |
class Page_Controller extends ContentController { | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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