简体   繁体   中英

How to get container instance in sonata Admin class (v 4.0.0-rc.1)?

$this->getConfigurationPool()->getContainer();

getContainer 方法在 4.0.0-rc.1 版本中似乎不存在

You could achieve this with dependency injection.

For example, I've injected ParameterBagInterface to get application params in my sonata admin.

use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;

class ProtocolAdmin extends AbstractAdmin
{
    private $params;

    public function __construct(string $code, string $class, string $baseControllerName, ParameterBagInterface $params)
    {
        parent::__construct($code, $class, $baseControllerName);
        $this->params = $params;
    }
  
    ...
}

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