I have found myself duplicating methods in a Model and its related Controler.
E.g.
Blog extends Page() {
function Posts($numPerPage) {
return DataObject::get("Post","BlogID=$this->ID","","",(int)$_GET['start'] . ", $numPerPage"");
}
}
Blog_Controller extends Page_Controller() {
function Posts() {
return DataObject::get("Post","BlogID=$this->ID","","",(int)$_GET['start'] . ", 8");
}
}
I was looking for a way to just use the function in the Model class and noticed that model class functions are inherited automatically,
E.g. just remove the Post function from the controler and the $this->Post() will call the function in the Model. However, parent does not seem to work like it does with other functions such as init().
E.g. the below call to parent::Posts() does not work, but parent::init() does work.
Blog_Controller extends Page_Controller() {
function init() {
parent::init();
}
function Posts($id) {
parent::Posts(8);
}
}
Any ideas on how to refernce the model function when you have a function with the same name in the controller?