简体   繁体   中英

Symfony 4 Service “Call to member function on null”

Using Symfony 4 and php7.2 Trying to use LoginFormAuthenticator ( https://knpuniversity.com/screencast/symfony-security ) and updating to Symfony 4 ( https://symfony.com/doc/current/security/guard_authentication.html ) No matter what I do, it appears that the dependency injection is not working for me. From documentation it seems simple: use autowire in config/services.yaml, put use statement for service in LoginFormAuthenticator.php file, put Type Hint argument in constructor

public function _construct(FormFactoryInterface $formFactory)
{
    $this->formFactory = $formFactory;
}

public function supports(Request $request)
{
    var_dump($this->formFactory);
}

The var_dump gives NULL

Trying to call a method on $this->formFactory gives error message:

Call to member function xyz on null

Tried autowire and tried using arguments without success.

Any suggestions?

您的构造函数应具有两个_ ,现在它具有一个_ ,因此它将不会运行,并且$formFactory为空,在这种情况下,您应首先检查构造是否运行

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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