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

ModelAdmin with list


Reply

8 Posts   2007 Views

Avatar
joelg

10 June 2009 at 1:53am Community Member, 129 Posts

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

Avatar
Ingo

14 June 2009 at 10:23pm Forum Moderator, 801 Posts

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

Avatar
joelg

22 March 2010 at 12:31am Community Member, 129 Posts

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

Avatar
Ingo

13 April 2010 at 8:40pm Forum Moderator, 801 Posts

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

Avatar
joelg

13 April 2010 at 8:54pm Community Member, 129 Posts

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

$default_search = true

just work?

Avatar
netnerd85

9 December 2010 at 4:12pm Community Member, 42 Posts

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

Avatar
dendeffe

9 December 2010 at 8:29pm Community Member, 135 Posts

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

Avatar
netnerd85

10 December 2010 at 10:52am Community Member, 42 Posts

Thanks dendeffe that worked great!