Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Get limit dataobject?

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

Page: 1
Go to End
Author Topic: 339 Views
  • bubu333
    Avatar
    Community Member
    8 Posts

    Get limit dataobject? Link to this post

    I have a project.
    ProjectPage.php
    class ProjectPage extends Page
    {

    static $has_many=array(
    'ProjectObjects'=>'ProjectObject '
    );
    ....
    }

    ProjectObject.php
    class ProjectObject extends DataObject
    {
    static $has_one=array(
    'ProjectPage=>'ProjectPage'
    );
    static $has_many=array(
    'ProjectImageObjects'=>'ProjectImageObject'
    );
    ....
    }
    ProjectImageObject.php

    class ProjectImageObject extends DataObject
    {
    static $has_one=array(
    'ProjectObject'=>'ProjectObject'
    );
    ....
    }

    In template ProjectPage.ss

    <% if ProjectObjects %>
    <% control ProjectObjects %>
    <p>$Content</p>
    <ul>
    <% control ProjectImageObjects %>
    <li>$Photo</li>
    <% end_control %>
    </ul>
    <% end_control %>
    <% end_if %>

    In above code,i have a relationship between ProjectPage.php and ProjectObject.php,ProjectObject.php and ProjectImageObject.php
    If i loop the relation's name it work fine but i want to get 2 projectimageobject so i write a function in ProjectPage_Controller
    public function getThreeProjectImageObjects()
    {
    return DataObject::get('ProjectImageObject','','ID ASC','',3);
    }
    but when i replace <% control ProjectImageObjects %>,<% control getThreeProjectImageObjects %>,it not work,i can't get image from projectimageobject...But if i take <% control getThreeProjectImageObjects %> block without <% if ProjectObjects %> block so it work fine.I dont understand.How i can get 3 image from projectimageobject in this case?Please help me

    339 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.