2016-03-15 114 views
0

形勢索納塔管理MongoDB的sonata_type_model_autocomplete

我有兩個文件

Company 
- id 
- staff (ReferenceOne Staff) 

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

有很多可能的工作人員的話,各地板我想轉換選擇2盒使用'sonata_type_mpde_autocomplete',但是,索納塔總是停止抱怨model_manager爲空。

我跟着從索納塔管理員在以下文件:https://sonata-project.org/bundles/admin/master/doc/reference/form_types.html#sonata-type-model-autocomplete

我看到有設置一個屬性,但在所有誠實我會放什麼呢?我會嘗試使用__toString()函數一次,這是工作,但下面的那一刻是我

我已經環顧四周,並創建了一個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); 
    } 
} 

在公司管理

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

在個人管理員中,我已經離開並將'firstName'添加到dataGrid過濾器。

$dataGridMapper 
    ->add('firstName'); 

回答

0

只需添加

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

期權陣列