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

VERY DUMB NEWBIE QUESTION


Go to End


2 Posts   943 Views

Avatar
servalman

Community Member, 211 Posts

27 June 2010 at 3:09am

Hello

I have this question but I can not find any clear answer :

In tutorial 2 you have this to create and return fields

<?php
 
class ArticlePage extends Page {
 
   static $db = array(
      'Date' => 'Date',
      'Author' => 'Text'
   );

 
   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;
   }
}
 

this works fine
my problem is the following when you want to build function in the Page_Controler how do you pass the field values to it
(maybe I don't get how this is workin

class ArticlePage_Controller extends Page_Controller {

function MyFunction () {

&myVar = SomefiledValue
}
 
}

I have been looking but did not find any simple answer to that

So if anyone ...

Thanks

Avatar
Willr

Forum Moderator, 5523 Posts

27 June 2010 at 11:44am

You are trying to get one of your database fields (date or author) ? SS has 'magic' getters so you could do

$date = $this->Date;

$date now has the Date database field. Or you can use a function to return the database object

$date = $this->dbObject('Date');