Advertisement
Guest User

Untitled

a guest
Mar 20th, 2013
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. StaffPage.php
  2. ================
  3.  
  4. <?php
  5.  
  6. class StaffPage extends Page {
  7.  
  8. public static $has_many = array(
  9. 'StaffMembers' => 'StaffMember',
  10. 'Departments' => 'Department'
  11. );
  12.  
  13. public function getCMSFields() {
  14. $fields = parent::getCMSFields();
  15.  
  16. $gridFieldConfig =$gridFieldConfig = GridFieldConfig_RecordEditor::create();
  17. $gridfield = new GridField("StaffMembers", "StaffMember", $this->StaffMembers(), $gridFieldConfig);
  18. $fields->addFieldToTab('Root.Staff', $gridfield);
  19.  
  20. $gridFieldConfig2 =$gridFieldConfig = GridFieldConfig_RecordEditor::create();
  21. $gridfield2 = new GridField("Departments", "Department", $this->Departments(), $gridFieldConfig2);
  22. $fields->addFieldToTab('Root.Departments', $gridfield2);
  23.  
  24. return $fields;
  25. }
  26.  
  27. }
  28.  
  29. class StaffPage_Controller extends Page_Controller {
  30. }
  31.  
  32. StaffMember.php
  33. ================
  34.  
  35. <?php
  36.  
  37. class StaffMember extends DataObject {
  38.  
  39. public static $db = array(
  40. 'Name'=>'Varchar',
  41. 'Details'=>'HTMLText'
  42. );
  43.  
  44.  
  45. public static $has_one = array(
  46. 'Image' => 'Image',
  47. 'Page' => 'Page',
  48. 'Department' => 'Department'
  49. );
  50.  
  51. // Summary fields
  52. public static $summary_fields = array(
  53. 'Thumbnail' => 'Thumbnail',
  54. 'Name' => 'Name'
  55. );
  56.  
  57. public function getThumbnail() {
  58. return $this->Image()->CMSThumbnail();
  59. }
  60.  
  61. }
  62.  
  63. Department.php
  64. ================
  65. <?php
  66.  
  67. class Department extends DataObject {
  68. public static $db = array(
  69. 'Name'=>'Varchar'
  70. );
  71.  
  72. public static $has_many = array(
  73. 'StaffMembers' => 'StaffMember'
  74. );
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement