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

$this->dataRecord->Fieldname versus $this->FieldName


Go to End


1592 Views

Avatar
aragonne

Community Member, 26 Posts

14 July 2010 at 10:30pm

Edited: 14/07/2010 10:33pm

Hi there,

Chapter 5 of the SilverStripe book by Ingo Schommer and Steven Broschart, specifically pages 149-150, states that to access a property of the model in the controller, the dataRecord property should be used. For example:

class MyPage extends Page {
static $db = array { 'MyField' => 'VarChar' };
function getCMS() { ... }
}

class MyPage_Controller extends Page_Controller {
$myField1 = $this->MyField;
$myField2 = $this->dataRecord->MyField;
}

myField1 and myField2 store the same content when echo'd out. What is the advantage of using dataRecord or is it used for other situations? Examples please.

thanks!