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.

Data Model Questions /

Where can I find Model admin


Reply


6 Posts   2062 Views

Avatar
mschiefmaker

Community Member, 187 Posts

12 May 2009 at 11:08pm

Hi
i need to Model Admin for some other modules I am trying to get to run but I can't work out where to download it from. Can someone help?

Thanks

MM

Avatar
rbquirke

Community Member, 70 Posts

13 May 2009 at 10:35am

ModelAdmin is built into SS 2.3.1, you don't need to download anything.

You just need to create your file that sets it up for your required data objects and adds a link to it in the CMS admin

Avatar
mschiefmaker

Community Member, 187 Posts

13 May 2009 at 2:03pm

Hey rbquirke

Thanks for the quick response. When you say you need to create a file that sets it up. What sort of file are we talking? Do you know of any documentaition which walks through set-up?

Thanks

MM

Avatar
rbquirke

Community Member, 70 Posts

13 May 2009 at 2:24pm

This doc covers it pretty well:
http://doc.silverstripe.com/doku.php?id=modeladmin

I also have a blog post here with a run down on some gotchas and links to a presentation on it:
http://www.cuplaweb.com/2009/03/trying-modeladmin-on-for-size/

That should get you started!

Avatar
mschiefmaker

Community Member, 187 Posts

29 May 2009 at 11:45am

Hey rbquirke

I followed the documentation you suggested but obviously not correctly as I get the following message when I try to flush the database

Uncaught exception 'ReflectionException' with message 'Class MyCatalogAdmin does not exist' in /var/www/html/SilverStripe/cms/code/CMSMenu.php:221 Stack trace: #0 /var/www/html/SilverStripe/cms/code/CMSMenu.php(221): ReflectionClass->__construct('MyCatalogAdmin') #1 /var/www/html/SilverStripe/cms/code/CMSMenu.php(19): CMSMenu::get_cms_classes() #2 /var/www/html/SilverStripe/cms/_config.php(19): CMSMenu::populate_menu() #3 /tmp/silverstripe-cache-var-www-html-SilverStripe/manifest-main(5921): require_once('/var/www/html/S...') #4 /var/www/html/SilverStripe/sapphire/core/ManifestBuilder.php(70): require_once('/tmp/silverstri...') #5 /var/www/html/SilverStripe/sapphire/core/Core.php(165): ManifestBuilder::include_manifest() #6 /var/www/html/SilverStripe/sapphire/main.php(58): require_once('/var/www/html/S...') #7 {main} thrown in /var/www/html/SilverStripe/cms/code/CMSMenu.php on line 221

I am using the example code just cut and pasted.

<?php

class MyCatalogAdmin extends ModelAdmin {

protected static $managed_models = array(
'Product',
'Category'
);

static $url_segment = 'products'; // will be linked as /admin/products
static $menu_title = 'My Product Admin';

}
class Product extends DataObject {

static $db = array(
'Name' => 'Varchar',
'ProductCode' => 'Varchar',
'Description' => 'Text',
'Price' => 'Currency'
);

static $has_one = array(
'Category' => 'Category'
);

static $searchable_fields = array(
'Name',
'ProductCode'
);
}
class Category extends DataObject {
static $db = array(
'Title' => 'Text'
);
}

Any ideas what I am doing wrong? I

Thanks as always

MM

Avatar
mschiefmaker

Community Member, 187 Posts

29 May 2009 at 2:31pm

That embarrassing ... had named the file MyCatalog not MyCatalogAdmin!

MM