7913 Posts in 1355 Topics by 930 members
|Go to End|
15 May 2009 at 10:16pm
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? ;)
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:
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.
|Go to Top|