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.

Archive /

Our old forums are still available as a read-only archive.

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

Custom fields not showing on CMS


Go to End


3 Posts   2830 Views

Avatar
aquafina

Community Member, 1 Post

26 November 2008 at 2:02pm

Hello,

I was following http://doc.silverstripe.com/doku.php?id=tutorial:2-extending-a-basic-site. I got the database built fine and I can create new page of type ArticleHolder and ArticlePage. However, when I'm on Article Page, I don't see new fields on CMS. I did flush on both http://mysite/db/build?flush=1 and http://mysite/admin/?flush=1.

I put the code to override getCMSFields() under mysite/code/ArticlePage.php under ArticlePage_Controller class. It seems like the function is not being called (I checked using syslog() on the function and I don't see anything)

Any pointers / help is appreciated.

Avatar
Willr

Forum Moderator, 5523 Posts

26 November 2008 at 6:54pm

It should be in the ArticlePage class and NOT the controller. The controller class usually only has methods which are used in the templates. Things like getCMSFields() should be in the top class.

Avatar
kudesign

Community Member, 64 Posts

11 December 2008 at 10:05am

I still have no luck adding the method to the ArticlePage class, this is my code in code/ArticlePage.php

<?php
/**
 * Defines the ArticlePage page type
 */
class ArticlePage extends Page {
   static $db = array(
   'Date' => 'Date',
   'Author' => 'Text'
   );
   static $has_one = array(
   );
}
function getCMSFields() {
   $fields = parent::getCMSFields();
 
   $fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
   $fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');
    	
   return $fields;
}
 
class ArticlePage_Controller extends Page_Controller {
 
}
 
?>

After db/build?flush=1 and multiple refreshes, it still does not show the Date and Author field when I tried to add a new ArticlePage in CMS. I'm on v2.2.3 What have I done wrong? Help!