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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Storing and Displaying a Collection of Testimonials


Go to End


35 Posts   8499 Views

Avatar
juneallison

Community Member, 110 Posts

12 July 2011 at 2:13am

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

Forum Moderator, 1899 Posts

12 July 2011 at 2:47am

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

Community Member, 110 Posts

12 July 2011 at 3:01am

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

Forum Moderator, 1899 Posts

12 July 2011 at 3:08am

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

Community Member, 110 Posts

22 July 2011 at 6:18am

@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

Forum Moderator, 1899 Posts

22 July 2011 at 10:51am

Avatar
juneallison

Community Member, 110 Posts

23 July 2011 at 6:37am

@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

Forum Moderator, 1391 Posts

25 July 2011 at 3:03am

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

Go to Top