简体   繁体   English

奏鸣曲 Admin 当前实体

[英]sonata Admin current entity

How can i access the id of a sonata admin entity.我如何访问奏鸣曲管理实体的 ID。 suppose i have an entity EndPoint which have a function getProject(), how can i get the id of that project.假设我有一个实体 EndPoint,它有一个 function getProject(),我怎样才能得到那个项目的 id。 I tried the code bellow but this gave me the following error: Attempted to call an undefined method named "getProject" of class "ContainerAgbGotv\srcApp_KernelDevDebugContainer".我尝试了下面的代码,但这给了我以下错误:尝试调用 class“ContainerAgbGotv\srcApp_KernelDevDebugContainer”的名为“getProject”的未定义方法。

class EndPointAdmin extends AbstractAdmin{
protected function configureFormFields(FormMapper $form)
{   $container = $this->getConfigurationPool()->getContainer();
    $em = $container->getProject();
    
    $array = [];
    foreach ($em as $ems) {
        if (!empty($ems->getEnv())) {
            $array[$ems->getEnv()] = $ems->getEnv();
        }}
    $result = array_unique($array);
    $form
        
        ->add('name',ChoiceType::class, [
            'choices'=> $result,
            'placeholder' => 'Choose an option',

            'required' => false
        ])
        ->add('ipAdress',TextType::class)
        ->add('port',IntegerType::class)
               ;
}

thanks for helping.谢谢你的帮助。

In an admin you will have access to在管理员中,您将有权访问

$this->getSubject()

which will return you the current entity for that admin.这将为您返回该管理员的当前实体。 It's worth noting configureFormFields is used for both creating and editing an entity so getSubject() may return null.值得注意的是 configureFormFields 用于创建和编辑实体,因此 getSubject() 可能会返回 null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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