Hi,
I have a list outputting from my database and I want to alphabetise it. I have followed the relations tutorial (no.5) and replicated this to suit my needs. Instead of mentor -> students, I have ingredientType -> Ingredient.
##INGREDIENT.PHP CODE##
<?php
class Ingredient extends DataObject {
static $db = array(
'IngredientName' => 'Text'
);
static $has_one = array(
'MyType' => 'IngredientType'
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField( 'IngredientName', 'Ingredient Name' ) );
return $fields;
}
}
?>
## INGREDIENTTYPE.PHP CODE ##
<?php
class IngredientType extends Page {
static $db = array(
'IngredientName' => 'Text'
);
static $has_many = array(
'Ingredients' => 'Ingredient'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'IngredientName', 'Ingredient Type' ) );
$tablefield = new HasManyComplexTableField(
$this,
'Ingredients',
'Ingredient',
array(
'IngredientName' => 'IngredientName'
),
'getCMSFields_forPopup'
);
$tablefield->setAddTitle( 'An Ingredient' );
$fields->addFieldToTab( 'Root.Content.Ingredients', $tablefield );
return $fields;
}
}
class IngredientType_Controller extends Page_Controller {
}
?>
##
Please can someone help me to sort this?
Much appreciated!!!
JK