Jump to:

23472 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Alphabetising Lists

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

Page: 1
Go to End
Author Topic: 794 Views
  • jk
    Avatar
    Community Member
    1 Post

    Alphabetising Lists Link to this post

    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

    794 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.