简体   繁体   English

Silverstripe-使模块从自定义页面类型扩展的最佳方法

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

My site structure is all custom page types with a single parent page the extends from Page.php. 我的网站结构是所有自定义页面类型,具有从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. 
}

Every other page in the site now extends from CustomPage and Custom_Controller respectively. 现在,站点中的所有其他页面分别从CustomPage和Custom_Controller扩展。 Page.php is pretty much empty. Page.php几乎是空的。

Now the problem comes when using modules that are not written internally. 现在,使用未在内部编写的模块时就会出现问题。 The Blog* module for example will not inherit the javascripts/css/functions defined in the new base class Custom_Controller as it is set to extend Page_Controller. 例如,Blog *模块将不会继承新基类Custom_Controller中定义的javascripts / css / functions,因为它被设置为扩展Page_Controller。

What is the ideal method here for basically making Blog_Controller extend Custom_Controller without modifying the Blog module? 从根本上使Blog_Controller扩展Custom_Controller而不修改Blog模块的理想方法是什么?

*Blog module is just an example. *博客模块只是一个例子。 this applies to all modules. 这适用于所有模块。

The short answer to the direct question 对直接问题的简短回答

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

is that it's not technically possible to do. 在技​​术上不可能做到这一点。 Effectively you've got two options; 实际上,您有两种选择;

  1. Make your changes to the Page/Page_Controller classes directly 直接对Page / Page_Controller类进行更改
  2. Inherit Page/Page_Controller in your custom page types, but rather than modifying Page directly, use an extension that is bound to Page to provide the custom behaviour for all sub-page types. 在自定义页面类型中继承Page / Page_Controller,而不是直接修改Page,而是使用绑定到Page的扩展来为所有子页面类型提供自定义行为。 For the specific case of providing custom init() behaviour, you'll want a custom extension that extends the Extension class, and is bound to Page_Controller 对于提供自定义init()行为的特定情况,您需要一个自定义扩展来扩展Extension类,并绑定到Page_Controller

Check into the extension documentation for a bit more information 查看扩展文档以获取更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM