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.

Data Model Questions /

Get limit dataobject?


Reply


465 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