简体   繁体   中英

reference to one Sonata Mongodb Admin Bundle

I'm working on a symfony2 web-app, I've installed sonata Mongodb admin Bundle.but I have a little problem, My data model is 'Quizz' document which references a 'QuizzTemplate' document (reference to One). This is my Code :

protected function configureListFields(ListMapper $listMapper)
 {
    $listMapper
    ->addIdentifier('uid')
    ->add('name')
    ->add('quizzTemplate', null, array("required" => false )
    ->add ('User', null, array('label' => 'Candidat','required' => false, 'by_reference' => true))
    ->add('_action', 'actions', array(
        'actions' => array(
            'view' => array(),
            'edit' => array(),
            )
        ))
    ;
}

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
    ->add('uid')
    ->add('name')  
    ->add('quizzTemplate', null, array());



}

protected function configureShowFields(ShowMapper $showMapper)
{

    $showMapper
        ->add('name')
        ->add('User')
        ->add('numericresult',null ,array('label' => 'Resultat Global'))

    ;

}


protected function configureDatagridFilters(DatagridMapper $datagrid)
{
    $datagrid
    ->add('uid')
    ->add('name') 

    ;
}

In fact it works for the list mapper but it is not the case with the configure and show and this is the error :

Error: Call to a member function getRepository() on a non-object

I tried it this way :

->add('quizzTemplate.id')

and i got this :

No document manager defined for class \\ATS\\QuizzBundle\\Document\\QuizzTemplate

Any one know how to fix this ? Thank you

I've just had the same issue with Sonata Mongodb. I'm using multiples connections and document managers.

Here is my first mistake, I've created an admin for an existing Document with the command app/console sonata:admin:generate , when prompt for The fully qualified model class I wrote \\Project\\MyBundle\\Document\\MyDocument . The rest of the process went fine, but at the very end, when the generator tried to generate MyDocumentAdmin class I got same error as you did :

No document manager defined for class \\Project\\MyBundle\\Document\\MyDocument

It took me some time to figure out what went wrong... I've created manually the admin class, and got the same error when trying to display the list.

In fact this error is due to a misspelling in the namespace, you need to remove the first character \\ in your class namespace in the arguments of the service sonata has generated.

Wrong syntax :

arguments: [~, \\MyProject\\MyBundle\\Document\\MyDocument , SonataAdminBundle:CRUD]

Good syntax :

arguments: [~, MyProject\\MyBundle\\Document\\MyDocument , SonataAdminBundle:CRUD]

Full working service definition:

my_project.admin.my_document:
        class: MyProject\MyBundle\Admin\MyDocumentAdmin
        arguments: [~, MyProject\MyBundle\Document\MyDocument, SonataAdminBundle:CRUD]
        tags:
            - {name: sonata.admin, manager_type: doctrine_mongodb, group: admin, label: MyDocument}

After this fix, everything is working fine again.

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