Jump to:

10994 Posts in 2728 Topics by 1819 members

All other Modules

SilverStripe Forums » All other Modules » ModelAdmin Issues

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 929 Views
  • Routh
    Avatar
    Community Member
    11 Posts

    ModelAdmin Issues Link to this post

    Ok, I've been learning Silverstripe and I've gone though the first tutorials. I've been using the book and the forums/documentation etc to learn everything, and so far so good. However I'm having some issues attempting to work with the ModelAdmin class for the first time, and I haven't really done much.

    I've created a quotes system that shows a random quote in the side bar on every page. I have a database of quotes and the sidebar module is working correctly. Now I want to make an admin tool to allow admin to manage the quotes, edit and add new ones. I've created an admin area with the following code:

    <?php
    class QuoteAdmin extends ModelAdmin {
       static $managed_models = array(
          'Quote'
       );
       static $searchable_fields = array(
          'Individual',
          'Occupation',
          'Topic',
          'Year',
          'Quote',
       );
       static $url_segment = 'quotes';
       static $menu_title = 'Quotes';
       static $model_importers = array(
          'Quote' => 'QuoteCsvBulkLoader',
       );

    }
    ?>

    I have two issues with this that I cannot seem to resolve.

    1: None of the search fields show. At all. Only one field shows called '#ID' (It is a drop down box that contains an entry for every quote in the db.

    2: None of the data fields show in the search results. Only #ID for each quote. However clicking the results shows the quotes and allows them to be edited.

    What am I missing? I'm assuming the two issues are related but I can't track down the answer. And yes, I know I'm a newb. ;)

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: ModelAdmin Issues Link to this post

    $searchable_fields should be attached to your model class (Quote), not the admin class.

  • Routh
    Avatar
    Community Member
    11 Posts

    Re: ModelAdmin Issues Link to this post

    Thanks for your reply.

    Thank fixed the search fields problem. However all the search results are still the same. The only field that shows in results is 'ID'. Reading documentation I can see how to customize the field names for each column in the results with $summary_fields. However reading the docs gives me the idea that this should only be needed if you want the fields to display something other than the column name, and otherwise should not be required.

    Is that correct?

  • Routh
    Avatar
    Community Member
    11 Posts

    Re: ModelAdmin Issues Link to this post

    I feel like a bit of a dolt now, after re-reading the doc file for 'DataObject'. I was lead to believe by reading ModelAdmin that I did not need to define $summary_fields, I realize now that it is required. Sorry, I should have rtfm a little more closely before asking.

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