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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Themes /

Discuss SilverStripe Themes.

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

Control limit in subpage(children).


Go to End


2 Posts   2182 Views

Avatar
kyhuuphat123

Community Member, 3 Posts

22 November 2012 at 3:56pm

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

Community Member, 68 Posts

18 December 2012 at 11:59pm

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.