Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Manage the Category Values?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1258 Views
  • SalvaStripe
    Community Member
    89 Posts

    Manage the Category Values? Link to this post

    hey there,
    is there a way to manage the Category values in the CMS?

    this is a part of Resource.php
       static $db = array (
          'Name' => 'Text',
          'Description' => 'Text',
          'Category' => "Enum('Industry, Finance, Education')"

    is it able to ADD / REMOVE / RENAME these Category in the CMS? when there are entries belong to an category that i want to delete, these entries should switch to an "holder" or "exil" category, or the category cant be deleted while there are entries belong to.

    hm.. someone? ;)

  • UncleCheese
    4085 Posts

    Re: Manage the Category Values? Link to this post

    Of course. First of all, you know that's just example code, right? It's by no means anything you have to use.

    If you want dynamic categories, you could do something like this:

    class ResourcePage extends Page
    static $has_many = array (
    'Categories' => 'ResourceCategory'

    // add to getCMSFields:
    new TableField(
    array('Name' => 'Name'),
    array('Name' => 'TextField')

    class ResourceCategory extends DataObject
    static $db = array ('Name' => 'Varchar(50'));
    static $has_one = array ('ResourcePage' => 'ResourcePage');

    class Resource extends DataObject
    static $has_one = array (
    'Category' => 'ResourceCategory'
    and then on your dropdown for categories, instead of the enumValues() function, just do this:

    $map = ($records = $this->ResourcePage()->ResourceCategories()) ? $records : array();
    $dropdown = new DropdownField('CategoryID','Resource category',$map);
    $dropdown->setEmptyString('-- Select category --');

    That's just pseudo code, but you get the idea.

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.