在SilverStripe 4中,当原始方法内没有扩展挂钩时,如何扩展现有方法? [英] In SilverStripe 4, how to extend an existing method when there is no Extension Hook inside the original method?

查看:87
本文介绍了在SilverStripe 4中,当原始方法内没有扩展挂钩时,如何扩展现有方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想覆盖'LoginHandler'类中的'loginForm'方法.我正在尝试使用下面给出的代码.但这是行不通的.

I want to override 'loginForm' method in 'LoginHandler' class. I am trying to use the code given below for that. But it is not working.

LoginHandlerExtension.php

LoginHandlerExtension.php

    <?php

    use SilverStripe\Core\Extension;

    class LoginHandlerExtension extends Extension {

        public function loginForm() {
            return 'xxxxxx';
        }
    }

app.yml

SilverStripe\Security\MemberAuthenticator\LoginHandler:
  extensions:
    - LoginHandlerExtension

推荐答案

您要在loginForm方法上覆盖什么?如果您希望它使用其他Form类(例如MyMemberLoginForm),则可以告诉Injector在YML中使用自定义类,如下所示:

What would you want to override on the loginForm method? If you want it to use a different Form class (e.g. MyMemberLoginForm), you can tell Injector to use your custom class in YML like this:

SilverStripe\Core\Injector\Injector:
  MemberLoginForm:
    class: My\Namespaced\LoginForm

因为LoginForm方法除了返回表单外没有做任何其他事情.

as the LoginForm method does nothing else but return the form.

这篇关于在SilverStripe 4中,当原始方法内没有扩展挂钩时,如何扩展现有方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆