Jump to:

23480 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Simple Testimonials page problem

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 603 Views
  • FireMe!
    Avatar
    Community Member
    74 Posts

    Simple Testimonials page problem Link to this post

    Hi all

    I am trying to create a simple testimonials page, with using the new gridfield in SS3 I am running 3.1.0 and I also have silverstripe-gridfield-betterbuttons module, my code bellow

    Testimonial.php

    <?php
    class Testimonial extends DataObject {

       public static $db = array(
          'Name' => 'Varchar(255)',
          'Testimonial' => 'Varchar(255)'
       );
       
       public static $has_one = array(
          'TestimonialsPage' => 'TestimonialsPage'
       );
       
       public function getCMSFields() {
              $fields = parent::getCMSFields();
             $fields->removeFieldFromTab("Root.Main","TestimonialsPageID");
             return $fields;      
        }

    }

    TestimonialsPage.php

    <?php
    class TestimonialsPage extends Page {

       public static $has_many = array(
          'Testimonials' => 'Testimonial' // Link the Testimonial Items
       );
       
       public function getCMSFields() {
          $fields = parent::getCMSFields();
          
           // Create a default configuration for the new GridField, allowing record editing
           $config = GridFieldConfig_RecordEditor::create();
           $config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
              'Name' => 'Name',
                      'Testimonial' => 'Testimonial'
           ));
           // Create a gridfield to hold the student relationship
           $testimonialsField = new GridField(
           'Testimonial', // Field name
           'Testimonials', // Field title
           $this->Testimonials(), // List of all related students
           $config
           );
           // Create a tab named "Students" and add our field to it
           $fields->addFieldToTab('Root.Testimonials', $testimonialsField);
           return $fields;
       }

    }
    class TestimonialsPage_Controller extends Page_Controller {

    }

    When I click save and add another button in CMS i get the below error in the CMS am I doing something wrong here? the record actually gets added also.

    Warning at line 673 of /framework/forms/gridfield/GridField.php

    Thanks in advance

    FireMe!

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: Simple Testimonials page problem Link to this post

    At first glance it all seems OK, I noticed a typo on the GirdField though. Missing an 's' off Testimonials.

    $testimonialsField = new GridField(
    'Testimonials', // Field name
    'Testimonials', // Field title
    $this->Testimonials(), // List of all related students
    $config
    );

    603 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.