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

ModelAdmin with list


Go to End


8 Posts   2756 Views

Avatar
joelg

Community Member, 134 Posts

10 June 2009 at 1:53am

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

Forum Moderator, 801 Posts

14 June 2009 at 10:23pm

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

Community Member, 134 Posts

22 March 2010 at 12:31am

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

Forum Moderator, 801 Posts

13 April 2010 at 8:40pm

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

Avatar
joelg

Community Member, 134 Posts

13 April 2010 at 8:54pm

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

$default_search = true
just work?

Avatar
jaybee

Community Member, 49 Posts

9 December 2010 at 4:12pm

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

Avatar
dendeffe

Community Member, 135 Posts

9 December 2010 at 8:29pm

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
jaybee

Community Member, 49 Posts

10 December 2010 at 10:52am

Thanks dendeffe that worked great!