Jump to:

5452 Posts in 1673 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » ModelAdmin with list

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

Page: 1
Go to End
Author Topic: 1890 Views
  • joelg
    Avatar
    Community Member
    129 Posts

    ModelAdmin with list Link to this post

    Hi Everyone

    I'm pretty new on ModelAdmin, but it's up and running and really great. However, instead of having this boring message: " Welcome to SilverStripe CMS. Please choose one of the entries in the left pane", I would like to show a list in the right pane based on the data in my ModelAdmin.

    These are my files:

    <?php
    class RegionsAdmin extends ModelAdmin {
       protected static $managed_models = array(
          'Region'   
       );
       static $url_segment = 'regioner'; // will be linked as /admin/mycrm
       static $menu_title = 'Regions';
    }
    ?>

    <?php
    class Region extends DataObject {
       static $db = array(
          'Navn' => 'Text',
          'Hovedstad' => 'Text',
          'Areal' => 'Text',
          'Indbyggere' => 'Text',
          'Vine' => 'Text'
       );
       static $searchable_fields = array(
          'Navn',
          'Hovedstad',
          'Areal',
          'Indbyggere',
          'Vine'
       );
       static $summary_fields = array(
          'Navn',
          'Hovedstad',
          'Vine'
       );
       function getCMSFields() {
          $fields = parent::getCMSFields();
          
          return $fields;
          }
       }
    ?>

    But how do I create a list based on my Regions class?

    Joel

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: ModelAdmin with list Link to this post

    You can overload the right template by adding a new Layout template called RegionAdmin_right.ss (see ModelAdmin_right.ss for clues on the necessary markup). You can then extend your RegionAdmin class the same way you would with any other template+controller combination to fetch a DataObjectSet and display it through a <% control %> in the template. Specifically for performing a search by default in ModelAdmin, please follow this ticket: http://open.silverstripe.com/ticket/3693

  • joelg
    Avatar
    Community Member
    129 Posts

    Re: ModelAdmin with list Link to this post

    Hi Ingo

    Did this feature about performing a search by default ever get implemented? If so, how do I get a search click by deafult?

    Joel

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: ModelAdmin with list Link to this post

    The ticket I've referenced in the post you've answered is still open, right? ;)

  • joelg
    Avatar
    Community Member
    129 Posts

    Re: ModelAdmin with list Link to this post

    Well, I tried, but nothing really happend. Should the

    $default_search = true

    just work?

  • netnerd85
    Avatar
    Community Member
    42 Posts

    Re: ModelAdmin with list Link to this post

    Anyone know how to get the "search by default" thing to work?

  • dendeffe
    Avatar
    Community Member
    135 Posts

    Re: ModelAdmin with list Link to this post

    You can do it with JavaScript. For instance for a ModelAdmin for a 'Product' DataObject:

    Javascript: http://pastie.org/1361257
    PHP: http://pastie.org/1361261

  • netnerd85
    Avatar
    Community Member
    42 Posts

    Re: ModelAdmin with list Link to this post

    Thanks dendeffe that worked great!

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