SIlverstripeNewbie
SIlverstripeNewbie

Reputation: 291

Custom fields not appearing

I am trying to add some custom fields to my page in the CMS, but the fields are not appearing.

I have run dev/build but they are still not appearing.

Why are my custom fields not appearing in the CMS?

<?php

class FieldPage extends Page {

    private static $db = array (
        'Field1' => 'Varchar(32)',
        'Field2' => 'Varchar(32)'
    );

    public function getCMSFields() {
        $fields = parent::getCMSFields();

        $fields->addFieldToTab('Root.Main', TextField::create('Field1', 'Field 1'));
        $fields->addFieldToTab('Root.Main', TextField::create('Field2', 'Field 2'));

        return $fields;
    }
}

class FieldPage_Contoller extends Page_Controller {

}

Upvotes: 0

Views: 336

Answers (1)

wmk
wmk

Reputation: 4626

Well, did you also flush on or before dev/build? Did dev/build end with the message "Database build completed!"? Scroll down at the very bottom of that page!

Can you confirm that in your database a new table with your classname (FieldPage in your example) with the database fields inside is created?

If yes, you still have to add a "FieldPage" to your CMS by hitting the "add new page" button. Then the fields should appear.

dev/build will break if you have any php errors in your code, then the database isn't changed for your need. The code pasted looks ok, but it could be a php error in any other class. So check if dev/build ends with the correct message.

Upvotes: 2

Related Questions