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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Alphabetising Lists


Go to End


1144 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