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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Get limit dataobject?


Go to End


1241 Views

Avatar
bubu333

Community Member, 8 Posts

22 November 2012 at 1:23am

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