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.

Template Questions /

Problem with Tutorial number 2


Reply


3 Posts   928 Views

Avatar
Boedlen

Community Member, 3 Posts

6 June 2010 at 2:24am

Hello everyone,

I've been following the Tutorial at http://doc.silverstripe.org/tutorials and i've now reached tutorial number 2, and i'm stuck at the part where i need to create the 2 new fields for the my ArticlePage.

I'm rather confident that i followed the tutorial 100%, but i simply can't get my fields to show in my ArticlePage in the adminitration.

I've created a new php file in mysite/code and named it "ArticlePage.php" and the content of the file is

<?php
/**
* Defines the ArticlePage page type
*/
class ArticlePage extends Page {
static $db = array(
   'Date' => 'Date',
   'Author' => 'Text'
);
static $has_one = array(
);
}

class ArticlePage_Controller extends Page_Controller {

}

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

$fields->addFieldToTab('Root.Content.Main', new DateField('Date'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');

return $fields;
}
?>

After i ran /dev/build i got this output which i assume menas that the fields where created in the database:

...
# Table ArticlePage: created
# Field ArticlePage.ID: created as int(11) not null auto_increment
# Field ArticlePage.Date: created as date
# Field ArticlePage.Author: created as mediumtext character set utf8 collate utf8_general_ci
# Table ArticlePage_Live: created
# Field ArticlePage_Live.ID: created as int(11) not null auto_increment
# Field ArticlePage_Live.Date: created as date
# Field ArticlePage_Live.Author: created as mediumtext character set utf8 collate utf8_general_ci
# Table ArticlePage_versions: created
# Field ArticlePage_versions.ID: created as int(11) not null auto_increment
# Field ArticlePage_versions.RecordID: created as int(11) not null default 0
# Field ArticlePage_versions.Version: created as int(11) not null default 0
# Field ArticlePage_versions.Date: created as date
# Field ArticlePage_versions.Author: created as mediumtext character set utf8 collate utf8_general_ci
# Index ArticlePage_versions.RecordID_Version: created as (RecordID,Version)
# Index ArticlePage_versions.RecordID: created as (RecordID)
# Index ArticlePage_versions.Version: created as (Version)
...

I tried both admin?flush=1 and dev/build multiple times, but the 2 new fields wont show up.
I've downloaded Silvestripe today, and it's version 2.4.0.

Is the tutorial outdated, or did i do do something wrong?

Hope someone can point me in the right direction since Silverstripe looks really awesome :-)

//Bødlen

Avatar
Boedlen

Community Member, 3 Posts

6 June 2010 at 2:54am

Problem solved!

I've placed the override function for getCMSFields, outside the ArticlePage class which was pretty stupid!
Thanks to ajshort @ IRC

// Boedlen

Avatar
Boedlen

Community Member, 3 Posts

6 June 2010 at 2:54am

Problem solved!

I've placed the override function for getCMSFields, outside the ArticlePage class which was pretty stupid!
Thanks to ajshort @ IRC

// Boedlen