簡體   English   中英

如何在 Sonata Admin 類 (v 4.0.0-rc.1) 中獲取容器實例?

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

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

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

您可以通過依賴注入來實現這一點。

例如,我已注入 ParameterBagInterface 以在我的奏鳴曲管理中獲取應用程序參數。

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;
    }
  
    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM