简体   繁体   English

Sonata管理员MongoDB sonata_type_model_autocomplete

[英]Sonata Admin MongoDB sonata_type_model_autocomplete

Situation 情况

I have two documents 我有两个文件

Company
- id
- staff (ReferenceOne Staff)

Staff
- id
- firstName (string)
- lastName (string)

There are a lot of possible staff so, all over the board I'm trying to convert the select2 boxes to use the 'sonata_type_mpde_autocomplete' but, Sonata is always halting on the complaing that the model_manager is null. 有很多可能的人员,所以,我试图将select2框全部转换为使用'sonata_type_mpde_autocomplete',但是,Sonata总是停止抱怨model_manager为null。

I followed the document from Sonata Admin at the following: https://sonata-project.org/bundles/admin/master/doc/reference/form_types.html#sonata-type-model-autocomplete 我在以下网址关注了Sonata Admin的文档: https : //sonata-project.org/bundles/admin/master/doc/reference/form_types.html#sonata-type-model-autocomplete

I see that there is a property to set but, in all honesty what would I put in the there? 我看到有一个要设置的属性,但是老实说,我会在其中放什么? I will try to use the __toString() function once this is working but for the moment below is what I have 一旦可行,我将尝试使用__toString()函数,但以下是我所拥有的

I have looked around and created a model_manager for staff 我环顾四周并为员工创建了model_manager

namespace AppBundle\ModelManager;

use Doctrine\ODM\MongoDB\DocumentManager;
use AppBundle\Repository\IndividualRepository;

class IndividualManager
{
  protected $dm;
  protected $repo;
  protected $class;

  public function __construct(DocumentManager $dm, $class)
  {
    $this->dm = $dm;
    $this->class = $class;
    $this->repo = $dm->getRepository($class);
  }
}

In the company admin 在公司管理员

->add('staff', 'sonata_type_model_autocomplete', array(
        'property' => 'firstName'))

In the individual admin, I've gone and added 'firstName' to the dataGrid filter. 在单个管理员中,我已经将“ firstName”添加到了dataGrid过滤器中。

$dataGridMapper
    ->add('firstName');

just add 只需添加

'model_manager' => $datagridMapper->getAdmin()->getModelManager(),

to options array 到选项数组

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

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