Hello,
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",
'Sort'
);
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'],
"URLSegment"=>$record['URLSegment'],
"ID"=>$record['ID'],
) ));
}
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">
<h2>$Title</h2>
<ul>
<% if BoxGetChildren %>
<% control BoxGetChildren %>
<li>
<a href="$Link" title="$Title"><h3>$MenuTitle</h3>
Dodano: $Created
</a>
</li>
<% end_control %>
<% end_if %>
</ul>
<a href="" title="" class="go_tabs">wszystkie</a>
</div>
<% end_control %>
And one extra question. What is the difference between defining methods in Page and Page_Controller class?