'Call to a member function get() on a non-object'?

前端 未结 2 1041
独厮守ぢ
独厮守ぢ 2020-12-10 18:33

Using symfony2. I have a listener class that is attempting to call a method from a different class (a controller) like so:

        $authenticate = new Authe         


        
2条回答
  •  遥遥无期
    2020-12-10 19:11

    I'm adding another answer because what @dev-null-dweller suggests is a bad practice: in almost every case you better to inject only the services you need — not the whole container:

    use Doctrine\DBAL\Connection;
    
    public function __construct(Connection $connection)
    {
        $this->connection = $connection;
    }
    
    my_listener:
        arguments: [ @database_connection ]
    

提交回复
热议问题