Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

Simple Testimonials page problem


Go to End


2 Posts   1668 Views

Avatar
FireMe!

Community Member, 74 Posts

7 May 2013 at 7:38am

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!

Avatar
Bambii7

Community Member, 254 Posts

9 May 2013 at 4:42pm

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
);