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.

Themes

Discuss SilverStripe Themes.

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

Control limit in subpage(children).


Reply

2 Posts   815 Views

Avatar
kyhuuphat123

22 November 2012 at 3:56pm Community Member, 3 Posts

I have page:

ProjectsAndServicesPage.php
RecentProjectObject.php
RecentProjectImagesObject.php
ProjectsAndServicesPage.ss

ProjectsAndServicesPage.php

class ProjectsAndServicesPage extends Page {

static $db = array(
);
static $has_one = array(
'ImageListProjects' => 'Image',
);
static $has_many = array(
'RecentProjectObject' => 'RecentProjectObject'
);
}

RecentProjectObject.php

class RecentProjectObject extends DataObject{
static $db = array(

);
static $has_one = array(
'ProjectsAndServicesPage'=>'ProjectsAndServicesPage'
);
static $has_many = array(
'RecentProjectImagesObject'=>'RecentProjectImagesObject'
);
}

RecentProjectImagesObject.php

class RecentProjectImagesObject extends DataObject {

static $db = array(
);
static $has_one = array(
'ImageRecentObject' => 'Image',
'RecentProjectObject' => 'RecentProjectObject',
);

}

ProjectsAndServicesPage.ss

<% control RecentProjectObject %>
<li<% if Last %>class="last"<% end_if %>>

<h3>$TitleProject</h3>
<p class="welcome">$WelcomeProject</p>
<ul class="clearfix">
<% control getRecentProjectImagesObjects %>
<li<% if Last %>class="last"<% end_if %>><a href="">$ImageRecentObject.CroppedImage(198,148)</a></li>
<% end_control %>
</ul>
<p><span>$Designer</span>$ContentDesigner</p>
<p><span>$ProjectManagement </span> $ContentProjectManagement</p>
<p><span>$ProjectManager </span>$ContentProjectManager </p>
<p><span>$Completed</span>$ContentCompleted</p>

</li>
<% end_control %>

ProjectsAndServicesPage.php
class ProjectsAndServicesPage_Controller extends Page_Controller {

function getRecentProjectImagesObjects($limit = 3) {
$url = $this->request->param('ID');
return DataObject::get("RecentProjectImagesObject", "RecentProjectObjectID='$url'", "ID Asc", "", $limit);
}

}

I write <% control getRecentProjectImagesObjects %>. This doesn't work. Please Help

Avatar
stallain

18 December 2012 at 11:59pm Community Member, 61 Posts

Hi,

In the template, you access your "RecentProjectImagesObjects" when looping through the "RecentProjectObject ". I think your "getRecentProjectImagesObjects" function should be written in "RecentProjectObject.php", not in the page controller.