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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

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


Reply


1109 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!