Skip to content

Instantly share code, notes, and snippets.

@sminnee
Created June 18, 2015 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sminnee/1f7260a349bc8bb863d8 to your computer and use it in GitHub Desktop.
Save sminnee/1f7260a349bc8bb863d8 to your computer and use it in GitHub Desktop.
Adding a GridField to SiteConfig
Add the following lines to the bottom of updateCMSFields();
<?php
$fields->addFieldToTab('Root.Quotes',
GridField::create('Quotes', 'Quotes',
InspirationalQuote::get(),
GridFieldConfig_RecordEditor::create())
);
<?php
class InspirationalQuote extends DataObject
{
private static $db = array(
"Quote" => "Text",
"Author" => "Varchar",
);
private static $summary_fields = array(
"Quote",
"Author"
);
}
Add this to Page_Controller.php
<?php
public function RandomQuote() {
return InspirationalQuote::get()->sort('RAND()')->first;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment