Created
June 18, 2015 13:03
-
-
Save sminnee/1f7260a349bc8bb863d8 to your computer and use it in GitHub Desktop.
Adding a GridField to SiteConfig
This file contains 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
Add the following lines to the bottom of updateCMSFields(); | |
<?php | |
$fields->addFieldToTab('Root.Quotes', | |
GridField::create('Quotes', 'Quotes', | |
InspirationalQuote::get(), | |
GridFieldConfig_RecordEditor::create()) | |
); |
This file contains 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 InspirationalQuote extends DataObject | |
{ | |
private static $db = array( | |
"Quote" => "Text", | |
"Author" => "Varchar", | |
); | |
private static $summary_fields = array( | |
"Quote", | |
"Author" | |
); | |
} |
This file contains 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
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