Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Template inner control section and method class

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

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

Page: 1
Go to End
Author Topic: 728 Views
  • Jarek
    Community Member
    30 Posts

    Template inner control section and method class Link to this post


    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?

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.