Jump to:

23023 Posts in 11882 Topics by 2830 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: 680 Views
  • Jarek
    Avatar
    Community Member
    30 Posts

    Template inner control section and method class Link to this post

    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?

    680 Views
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.