Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class PostPage extends Page {
- public static $db = array(
- 'Title' => 'Text'
- );
- public static $many_many = array(
- 'Authors' => 'AuthorPage'
- );
- public function getCMSFields() {
- $fields = parent::getCMSFields();
- // Get all Campuses (locations)
- $campuses = AuthorPage::get();
- // Create a map(array) with the format array(ID=>Title). This is the default as per
- // http://api.silverstripe.org/3.0/class-DataList.html#_map
- $map = $campuses->map();
- // Create a CheckboxSetField to select course locations
- $courseLocations = new CheckboxSetField('Authors', 'Choose course locations', $map);
- // Add the CheckboxSetField to the CMS
- $fields->addFieldToTab('Root.Main', $courseLocations, 'Content');
- $fields->addFieldToTab('Root.Main', new TextField('Title'), 'Content');
- return $fields;
- }
- }
- class AuthorPage extends Page {
- public static $db = array(
- 'Name' => 'Text'
- );
- public static $many_many = array(
- 'Posts' => 'PostPage'
- );
- public function getCMSFields() {
- $fields = parent::getCMSFields();
- $fields->addFieldToTab('Root.Main', new TextField('Name'), 'Content');
- return $fields;
- }
- }
- class HomePage_Controller extends Page_Controller {
- public function filterStuff() {
- $results = PostPage::get()->filter(array('Authors.ID:ExactMatch' => 1));
- return $results->renderWith('SomeTemplate');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement