Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Alphabetising Lists


Reply


820 Views

Avatar
jk

Community Member, 1 Post

11 August 2010 at 6:24am

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