Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » PHP Inheritance

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1374 Views
  • xmedeko
    Avatar
    Community Member
    94 Posts

    PHP Inheritance Link to this post

    Hi,

    I have a class

    class Page_Controller extends ContentController {

    /**
    * @returns - sorted children according to the given criteria
    */
    public function reverseChildren($field, $direction) {
    $children = $this->Children();
    $children->sort($field,$direction);
    return $children;
    }

    }

    and then a class

    class ArticleHolder_Controller extends Page_Controller { ... }

    I use

    <% control reverseChildren(Date,DESC) %> in ArticleHolder.ss template, but it does nothing. When I move (or copy) the function reverseChildren from the Page_Controller class to the ArticleHolder_Controller class, then it works fine. I have tried to flush DB, flush the page, but still the same weird behaviour. Any clue?

    Thanks

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: PHP Inheritance Link to this post

    i think you've came across a limitation of our template-parser - it doesn't handle two arguments on <% control %>-blocks. as a workaround, you can create alias-methods such as "ChildrenByDate" etc.

    btw, our coding conventions state that you should name template-accessors upper camelcase (http://doc.silverstripe.com/doku.php?id=coding-conventions). its a bit hidden, in "Classes->Class Organisation":
    "Template data-access methods (methods that will be called by a $MethodName or <% control MethodName %> construct in a template somewhere)".

  • xmedeko
    Avatar
    Community Member
    94 Posts

    Re: PHP Inheritance Link to this post

    Hi,
    I do not think this is the problem with two or more arguments. Now I have

    class Page_Controller extends ContentController {
    function GetBlogTags() {
    return DataObject::get("BlogTag",
              $filter = "",
              $sort = "Title ASC",
              $join = "",
              $limit = "");
    }
    }

    I use this code

    <% control GetBlogTags %> ... <% end_control %>

    in a sidebar included in all my pages. All my pages extends Page_Controller. But the proper result is shown only when I copy this code to all my controller classes.

  • xmedeko
    Avatar
    Community Member
    94 Posts

    Re: PHP Inheritance Link to this post

    Oh, I have solved that mysterious problem with inheritance. A couple of days ago I have copied a directory "mysite" to "mysite.orig" and I have continued working in "mysite" directory. The autoload function has loaded a class Page.php from the "mysite.orig" and not from "mysite".

  • Sigurd
    Avatar
    Forum Moderator
    628 Posts

    Re: PHP Inheritance Link to this post

    Sweet. As a side-note, we'll be making it easier to disable the folders when not needed, probably by detecting whether or not you have a _config.php in the folder. See my 202 installation ideas I posted a few hours ago.

    1374 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.