Jump to:

3372 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Where can I find Model admin

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

Page: 1
Go to End
Author Topic: 1975 Views
  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Where can I find Model admin Link to this post

    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

  • rbquirke
    Avatar
    Community Member
    70 Posts

    Re: Where can I find Model admin Link to this post

    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

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Where can I find Model admin Link to this post

    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

  • rbquirke
    Avatar
    Community Member
    70 Posts

    Re: Where can I find Model admin Link to this post

    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!

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Where can I find Model admin Link to this post

    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

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Where can I find Model admin Link to this post

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

    MM

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