Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » trouble accessing data object via page controlls

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

Page: 1
Go to End
Author Topic: 1021 Views
  • snoopy
    Avatar
    Community Member
    4 Posts

    trouble accessing data object via page controlls Link to this post

    Hi!

    I'm trying to set up a page modifying the example in tutorial 5, but now I got stuck... I'd really appreciate if someone could help me out...

    So, I extended the data object like this:

    class Teacher extends DataObject {

    static $db = array(
    'FirstName' => 'Text',
    'LastName' => 'Text',
    'Email' => 'Text',
    'PersonalInfo' => 'Text'
    );

    static $has_one = array(
    'MyTeacher' => 'TeacherPage',
    'Photo' => 'Image'
    );

    function getCMSFields_forPopup() {
    $fields = new FieldSet();
    $fields->push( new TextField('FirstName', 'Vorname'));
    $fields->push( new TextField('LastName', 'Nachname'));
    $fields->push( new TextField('Email', 'Email'));
    $fields->push( new TextAreaField('PersonalInfo', 'Persönliche Informationen'));
    return $fields;
    }
    }

    Then I created a page in order to contain all this information:

    class TeacherPage extends Page {

    static $db = array();

    static $has_many = array(
    'MyTeachers' => 'Teacher'
    );
       
    function getCMSFields() {
    $fields = parent::getCMSFields();

    $tablefield = new HasManyComplexTableField(
    $this,
    'MyTeachers',
    'Teacher',
    array( 'FirstName' => 'Vorname',
    'LastName' => 'Nachname',
    'Email' => 'Email',
    'PersonalInfo' => 'Persönliche Infos'),
    'getCMSFields_forPopup'
    );
    $tablefield->setAddTitle( 'Lehrer' );
    $fields->addFieldToTab( 'Root.Content.Lehrer', $tablefield);
    return $fields;
    }
    }

    The cms looks just fine and I can add all the information that I want. But when I'm trying to display all this information, I run into troubles... I don't know how to access the data, correctly... I thought it was supposed to look like this.

    <div id="TeachersList">
    <% if MyTeachers %>
    <% control MyTeachers %>
    <div class="TeacherInfo">
    <h3>$FirstName $LastName</h3>
    </div>
    <% end_control %>
    <% else %>
    nothing found
    <% end_if %>
    </div>

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: trouble accessing data object via page controlls Link to this post

    That all looks fine. What trouble are you having? Ie, what does it display?

    1021 Views
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.