银条纹-使模块从自定义页面类型扩展的最佳方式


Silverstripe - Best way to make a module extend from custom page type

我的网站结构都是自定义页面类型,只有一个从page.php扩展而来的父页面。

class CustomPage extends Page {}
class  Custom_Controller extends Page_Controller {
    //load all javascript/css for entire site here etc
}

class SomeClass extends CustomPage {}
class SomeClass_Controller extends Custom_Controller
{
    // etc etc you get the point. 
}

站点中的其他页面现在分别从CustomPage和Custom_Controller扩展。Page.php几乎是空的。

现在,当使用非内部编写的模块时,问题就来了。例如,Blog*模块将不会继承在新基类Custom_Controller中定义的javascripts/css/函数,因为它被设置为扩展Page_Coontroller。

在不修改博客模块的情况下,基本上使Blog_Controller扩展Custom_Controller的理想方法是什么?

*博客模块只是一个例子。这适用于所有模块。

直接问题的简短答案

What is the ideal method here for basically making Blog_Controller extend Custom_Controller without modifying the Blog module?

实际上,你有两种选择;

  1. 直接更改Page/Page_Controller类
  2. 在自定义页面类型中继承Page/Page_Controller,但不要直接修改Page,而是使用绑定到Page的扩展为所有子页面类型提供自定义行为。对于提供自定义init()行为的特定情况,您需要一个扩展Extension类并绑定到Page_Controller的自定义扩展

查看扩展文档以获取更多信息