7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Manage the Category Values?
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1108 Views |
-
Manage the Category Values?

15 May 2009 at 10:16pm
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? ;)
-
Re: Manage the Category Values?

16 May 2009 at 3:35am
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(
$this,
'Categories',
'ResourceCategory',
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.
| 1108 Views | ||
|
Page:
1
|
Go to Top |
