In SilverStripe 4, how to extend an existing metho

2019-07-09 08:12发布

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

    <?php

    use SilverStripe\Core\Extension;

    class LoginHandlerExtension extends Extension {

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

app.yml

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

1条回答
\"骚年 ilove
2楼-- · 2019-07-09 08:43

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

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

查看更多
登录 后发表回答