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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Template inner control section and method class

Go to End



Community Member, 30 Posts

11 August 2010 at 12:08am


I've code, which is getting n-latest news from subpages. In HomePage_Controller there is method (with standard get):

function boxses()
$boxses = DataObject::get("Page",
"showHomeBox = 1",

return $boxses ? $boxses : false;

in Page class there is function used in template sub control

function BoxGetChildren()
$boxses = DataObject::get("Page", "ParentID = $this->ID", "Created DESC", Null, 3);

return $boxses ? $boxses : false;

everything is ok. But when I change first function (I want to get also parent URLSegment) to this:

function boxses()
$sqlQuery = new SQLQuery();
$sqlQuery->select = array("par.URLSegment, st.Title, st.ID");
$sqlQuery->from = array("SiteTree_Live st JOIN Page_Live USING (ID) JOIN SiteTree_Live par ON (par.ID = st.parentID)");
$sqlQuery->where = array("showHomeBox = 1");
$sqlQuery->orderby = "";

$res = $sqlQuery->execute();
$dos = new DataObjectSet();
foreach ($res as $record)

$dos->push( new DataObject( array("BoxTitle"=>$record['Title'],
) ));

return $dos ? $dos : false;

second function doesn't fire, why? I think that returned DataObjectSet has no "type", and template engine doesn't know where should look for BoxGetChildren method.

This is template code:

<% control boxses %>
<div class="main_box">
<% if BoxGetChildren %>
<% control BoxGetChildren %>
<a href="$Link" title="$Title"><h3>$MenuTitle</h3>
Dodano: $Created
<% end_control %>
<% end_if %>
<a href="" title="" class="go_tabs">wszystkie</a>
<% end_control %>

And one extra question. What is the difference between defining methods in Page and Page_Controller class?