问题
I've been looking for what is going wrong for days now; I followed the documentation from the sonata website and repeated it several times, but my dashboard is still empty. After writing my AdminClass
and Services
(and setup the config.yml
), I regenerate entities and updated my schema, but Sonata created a table in my DB for entities that I wanted to be in admin
.
Here is my code for App/Config/Config.yml
( top of file for imports )
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: @materniteamAppBundle/Resources/config/admin.yml }
- { resource: @materniteamUserBundle/Resources/config/admin.yml }
App/Config/Config.yml
( bottom of file with sonata config )
# FOS USER
fos_user:
db_driver: orm
firewall_name: main
user_class: materniteam\UserBundle\Entity\User
# ADMIN SONATA
sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
sonata.block.service.text:
sonata.block.service.action:
sonata.block.service.rss:
sonata_admin:
title: Materniteam
security:
handler: sonata.admin.security.handler.role
acl_user_manager: fos_user.user_manager
Here is my Admin Class for entity Contact //src/APP/APPBundle/Admin/ContactAdmin.php
:
<?php
namespace materniteam\AppBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
class ContactAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('prenom')
->add('nom')
->add('adresse')
->add('codePostal')
->add('ville')
->end()
;
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('Nom')
->add('prenom')
->add('adresse')
->add('codePostal')
->add('ville')
->add('_action', 'actions', array(
'actions' => array(
'view' => array(),
'edit' => array(),
'delete' => array(),
)
))
;
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('prenom')
->add('nom')
->add('adresse')
;
}
}
?>
and finally here is my service call //src/APP/APPBundle/Resources/config/admin.yml
services:
materniteam.app.admin.contact:
class: materniteam\AppBundle\Admin\ContactAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "App", label: "Contact" }
arguments: [ null, materniteam\AppBundle\Entity\Contact, SonataAdminBundle:CRUD ]
like I said, I have no errors, but the dashboard is still not listing my entities. If you need more code, just ask and I'll edit this message.
If any Sonata group member is reading this :
PLEASE UPDATE YOUR DOCUMENTATION !!!
回答1:
It seems the problem occurs with the security part of sonata.
In my config.yml , i set the security of sonata with the following values :
security:
handler: sonata.admin.security.handler.role
which tells sonata to use security based on user roles ( which i think is great ) I succeeded to see my entities in sonata by replacing the handler by the following
security:
handler: sonata.admin.security.handler.noop
which tells sonata to use Symfony based security. ( i had btw to promote my user to ROLE_ADMIN to continue accessing sonata dashboard )
回答2:
Try this in sonata admin block
sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
sonata.block.service.text:
sonata.block.service.action:
sonata.block.service.rss:
来源:https://stackoverflow.com/questions/19445451/symfony-2-3-6-and-sonata-admin-bundle-empty-dashboard-and-no-errors