Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Storing and Displaying a Collection of Testimonials

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

Page: 1 2 3 4 5
Go to End
Author Topic: 4917 Views
  • juneallison
    Avatar
    Community Member
    108 Posts

    Storing and Displaying a Collection of Testimonials Link to this post

    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!

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    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!

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    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!

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    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...

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    @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!

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts
  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    @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!

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

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

    4917 Views
Page: 1 2 3 4 5
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.