- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我注意到在某些情况下,当您编写一个扩展现有类的类时,您需要在 config.yml 文件中声明类扩展。
例如,我最近写了这段代码来删除 CMS 后端的“帮助”按钮。
mysite/code/Tweak.php
class Tweak extends LeftAndMainExtension
{
public function init()
{
parent::init();
/* Remove help link */
CMSMenu::remove_menu_item('Help');
}
}
mysite/code/Config.yml
LeftAndMain:
extensions:
- Tweak
问题一:为什么有些类扩展需要在config.yml中声明?为什么其他类扩展(例如扩展 DataObject 或 Page_Controller)不需要这个额外的步骤?
问题 2: 关于上述代码的具体问题,为什么我在配置文件中将 Tweaks 声明为 LeftAndMain 的扩展,但在我实际上正在扩展 php 文件 LeftAndMainExtension?
最佳答案
Question 1: Why do some class extensions need to be declared in config.yml? And why is this extra step not necessary for other class extensions (eg extending DataObject or Page_Controller)?
PHP 和 SilverStripe 术语之间存在重要区别。
在 SilverStripe 中,Extension 是一种在 SilverStripe 中实现的框架功能,它允许您修改对象的行为,而无需访问除公共(public)内容以外的任何内容。在这方面它与 Ruby 类似。
在 PHP 中,您可以使用 extends
关键字来定义现有类的子类。
在您的示例中,您使用的是 LeftAndMainExtension
,这是一个 SilverStripe“扩展”- 这允许您修改 SilverStripe 管理区域中 CMS 菜单的行为,而它不会 从字面上扩展(用 PHP 术语)LeftAndMain
类。
Question 2: Specific question about above code, why am I declaring Tweaks as an extension to LeftAndMain in the config file, but in the php file I'm actually extending LeftAndMainExtension?
如上所述,这就是 SilverStripe 的扩展系统的工作原理。它基本上遵循以下过程:
扩展
(PHP 关键字)Extension
的类(您使用LeftAndMainExtension
,它扩展了扩展名
)。对于 DataObject,您可以使用 DataExtension
。LeftAndMain
命名是经过深思熟虑的,因此您可以轻松/直观地将对象及其相关扩展组合在一起:
Convention is for extension class names to end in Extension. This isn't a requirement but makes it clearer
- SilverStripe developer documentation
请注意,我故意将 Extension 大写以表示它是一个 SilverStripe 扩展类,而不是一个类的 PHP 扩展(class Foo extends Bar
)。
框架如何执行这个过程的例子,基本上是这样的:
Object::add_extension()
应用的扩展)进行扩展$this->owner
设置为当前对象,以便扩展可以从中访问公共(public)方法和属性关于php - config.yml 中的 SilverStripe 类扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38211308/
任何人都可以详细说明用途是什么(何时使用)asp.net web应用中的web.config,web.config.debug,web.config.release文件?? 最佳答案 它是用于更改调试
我正在尝试创建一个 nuget 包,它将添加一个 DLL 并在正确的配置文件中配置它。该包可用于控制台/表单应用程序或 Web 应用程序,因此我想更新相应的配置文件,app.config 或 web.
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 有关您编写的代码问题的问题必须在问题本身中描述具体问题 - 并包含有效代码 以重现它。
我正在开发一个 MVCPortlet。我的 view.jsp 中有一个链接,它调用 liferay 中 portlet 类中的一个方法。 ">Comlex This is the Refahi
我一直在尝试了解如何使用不同的配置文件,我刚刚发现 this link这非常有帮助。唯一的问题是,似乎只有在“发布”解决方案时才会考虑转换,而如果您现在只是进行通用调试或运行,则不会考虑转换。 通常这
我想处理我的 jsx 代码,所以我像这样编写 webpakc.config.js: { test: /\.js$/, loaders: ['react-hot', 'babel-loa
我正在使用 Web.Config 转换将我的应用程序部署到 Azure。我的服务中还有 2 个站点,一个公共(public)网站和一个私有(private) WCF 站点端点。我正在部署multipl
我正在使用 spring security 4.2.5.RELEASE 和 spring 4.3.16.RELEASE我的 XML 配置工作正常,如下所示
config.json 和 config.js 之间有什么区别?我必须同时使用两者吗?我什么时候需要使用其中之一? (https://docs.strongloop.com/display/publi
我运行了 Doctrine 控制台工具: $ php vendor/doctrine/orm/bin/doctrine orm:schema-tool:create --dump-sql 我得到了这个
我正在尝试将 Doctrine ORM 与 Silex 一起使用,但由于缺乏一致的文档,我发现这是一种完全令人沮丧的体验。 当我在控制台运行 vendor/bin/doctrine 时,我得到以下输出
我需要在 web.config 中的多个 WCF 服务中切换出一个 IP 地址。使用 web.config 转换,除了通过 xpath 指定每个地址之外,还有什么方法可以创建搜索和替换语句。例如。对于
我使用来自Ubuntu 14.04的tmux(tmux 1.8)。 我想通过~/.tmux.conf对其进行一些配置。但是无论我在该文件中设置的内容如何,tmux session 都相同。然后,我
嗨,我正在尝试将我的域别名重定向到一个域。 我目前有这个规则 当别名前面没有 www 时它工作得很好.. 我怎么说重定向所有不等于这个域的 谢
我的 Web 配置中有以下 XML,在 Release模式下,我需要根据其子项的名称属性删除 dependentAssembly 部分:assemblyIdentity。我在这里尝试了答案:xdt t
我正在为 web.config 文件寻找一个轻量级的文本编辑器,它具有颜色语法突出显示(如在 Visual Studio 中)。 有什么建议? 最佳答案 您可以使用 Notepad++ .当您使用 w
ImagePicker This plugin allows selection of multiple images from the camera roll
ImagePicker This plugin allows selection of multiple images from the camera roll
如果我有一个 Web 应用程序(有它自己的 web.config )和一个它使用的 .dll 恰好有它自己的 app.config 发生冲突时哪个设置文件会胜出? 最佳答案 不,您不会有任何冲突,因为
问题描述: 我正在尝试在 bash 脚本中使用终止符,但我不断收到一条错误消息,指出没有这样的文件或目录:~/.config/terminator/config .并防止终端在屏幕上弹出。但是,当我在
我是一名优秀的程序员,十分优秀!