Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » $this->dataRecord->Fieldname versus $this->FieldName

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

Page: 1
Go to End
Author Topic: 1057 Views
  • aragonne
    Community Member
    26 Posts

    $this->dataRecord->Fieldname versus $this->FieldName Link to this post

    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.


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.