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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

PHP Inheritance


Go to End


5 Posts   1928 Views

Avatar
xmedeko

Community Member, 94 Posts

18 May 2007 at 12:04pm

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

Avatar
Ingo

Forum Moderator, 801 Posts

21 May 2007 at 10:40pm

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)".

Avatar
xmedeko

Community Member, 94 Posts

22 May 2007 at 3:16pm

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.

Avatar
xmedeko

Community Member, 94 Posts

23 May 2007 at 9:37am

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

Avatar
Sigurd

Forum Moderator, 628 Posts

23 May 2007 at 10:40am

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.