17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1259 Views |
-
PHP Inheritance

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
-
Re: PHP Inheritance

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)". -
Re: PHP Inheritance

22 May 2007 at 3:16pm
Hi,
I do not think this is the problem with two or more arguments. Now I haveclass 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.
-
Re: PHP Inheritance

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".
-
Re: PHP Inheritance

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.
| 1259 Views | ||
|
Page:
1
|
Go to Top |



