Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » ModelAdmin user error

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 3464 Views
  • Howard
    Avatar
    Community Member
    215 Posts

    ModelAdmin user error Link to this post

    Hi guys,

    I am looking into how to use modeladmin now that there is some documentation to it.

    I have done a clean install from the 2.3 branch then created 3 files in mysite/code:

    ProductsHolder.php

    <?php
    class ProductsHolder extends Page {
    static $allowed_children = array( 'Product' );
    }

    class ProductsHolder_Controller extends Page_Controller {
    }
    ?>

    Product.php

    <?php

    class Product extends DataObject {

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

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

    static $searchable_fields = array(
    'Name',
    'ProductCode'
    );

    }

    ?>


    and MyCatalogAdmin.php

    <?php

    class MyCatalogAdmin extends ModelAdmin {

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

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

    }

    ?>

    After db build I log into the admin and am able to select "My Product Admin" which then appears to load fine until I click on "Create 'Product'" it shows an error message:

    Error: "Bad class to singleton() - Category" at line 263 of /Users/Howard/Desktop/localhost/jdmnz/sapphire/core/Core.php

    the line from core.php in question reads:

    if(!class_exists($className)) user_error("Bad class to singleton() - $className", E_USER_ERROR);

    Any help would be greatly appreciated!

  • jam13
    Avatar
    121 Posts

    Re: ModelAdmin user error Link to this post

    Think your problem might be here:

    static $allowed_children = array( 'Product' );

    Product is not derived from SiteTree, so I don't think this will work.

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