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.

Customising the CMS

Storing and Displaying a Collection of Testimonials


Go to End
Reply

35 Posts   4977 Views

Avatar
juneallison

12 July 2011 at 2:13am Community Member, 108 Posts

Hi,

I have a general question about the best place to store data. Basically I have a pool of testimonials that will be displayed in the header area of my website. I guess I need some general input on the best place to store and edit this data in the admin area. Each testimonial will have the following data: the text, the author, and tags. The tags will allow me to display/rotate through certain testimonials on certain pages/sections.

Is this documentation a good starting point:
http://doc.silverstripe.org/sapphire/en/reference/modeladmin

... or are there other things I should consider for this sort of functionality?

Thanks!

Avatar
swaiba

12 July 2011 at 2:47am Forum Moderator, 1796 Posts

Hi,

ModelAdmin is great, it isn't for everyone though... there is a nice presentation by ingo on it... http://www.silverstripe.org/making-a-crm-with-modeladmin-in-silverstripe-230/

I'd also recommend trying the siteconfig to do the job... http://www.ssbits.com/tutorials/2010/2-4-working-with-siteconfig/ if you are only after small amounts of data that will only ever be for presentation on the website then it's perfect.

Also there is a module for tags... http://www.silverstripe.org/tag-field-module/

Hope this helps!

Avatar
juneallison

12 July 2011 at 3:01am Community Member, 108 Posts

swaiba - this is all very helpful! thanks so much!

I'm afraid the data I need to store is too extensive for Site Config. But it didn't occur to me to add fields there, so that will come in handy. I will likely have some other bits of information that will fit perfectly here.

I'll take a look at the Model Admin presentation too.

And thats for sharing the tag module link. that's perfect! One question about the tag module. I already have the blog module installed. This won't interfere with the blog's tagging, right?

thanks!

Avatar
swaiba

12 July 2011 at 3:08am Forum Moderator, 1796 Posts

One question about the tag module. I already have the blog module installed. This won't interfere with the blog's tagging, right?

Sorry I have no idea - don't use the blog module - instead a separate installation of wordpress and I pull the data from there. You can however find out by installing the module and as long as nothing funny happens during a dev build - it'll probably be fine...

Avatar
juneallison

22 July 2011 at 6:18am Community Member, 108 Posts

@swaiba - So I've decided to use the model admin for my testimonials. I have most of it working. I'm just getting a little bit stuck on the categories/tags. I would like to create and manage these via the model admin instead of using the tags module.

Here is what I have so far:

MyTestimonialAdmin.php

<?php
class MyTestimonialAdmin extends ModelAdmin {
public static $managed_models = array(
'Testimonial',
'Category'
   );
   static $url_segment = 'testimonials';
   static $menu_title = 'My Testimonial Admin';
}
?>

Testimonial.php

<?php
class Testimonial extends DataObject {
   static $db = array(
    'Name' => 'Varchar',
'Quote' => 'Text',
'Signature' => 'Text'
);
   static $many_many = array(
'Categories' => 'Category'
);
   static $searchable_fields = array(
      'Name',
      'Quote',
   'Signature'
);
   static $summary_fields = array(
      'Name',
      'Quote',
      'Signature'
   );
}
?>

Category.php

<?php
class Category extends DataObject {
static $db = array(
'Title' => 'Text'
);

static $belongs_many_many = array(
   'Testimonials' => 'Testimonial',
);
}
?>

A category can have many testimonials and a testimonial can have many categories so I went the many_many approach. I'm not sure if this is right.

Looking at the admin interface I can easily add categories (in general). But if I add a testimonial and click to the "Categories" tab it does not show me my existing categories. I'd like to be able to check the categories that correspond with the testimonial.

Any suggestions you have would be great. Thanks!

Avatar
swaiba

22 July 2011 at 10:51am Forum Moderator, 1796 Posts

I'd suggest using this...
http://silverstripe.org/multiselectfield-module/

Avatar
juneallison

23 July 2011 at 6:37am Community Member, 108 Posts

@swaiba - I just downloaded an installed the MultiSelectField module.

I just added:

   $source = DataObject::get('Categories');
    new MultiSelectField(
    "Categories", // Relationship
    "Testimonial Categories", // Field name
    $source->map('ID','Title') // Source records (array)
    );

...to the Testimonial.php file. After adding this code I can't even rebuild my database. It just hangs at the category table. Is my syntax above correct or am I missing something?

Thanks!

Avatar
martimiz

25 July 2011 at 3:03am Forum Moderator, 1091 Posts

Should probably be Dataobject::get('Category');

Go to Top