При настройке Sonata Admin Bundle + Sonata User Bundle + MongoDB у меня возникли проблемы с Sonata User Bundle. Поэтому, был бы признателен всем, кому удалось настроить эту связку прислать свои настройки.
А пока, выкладываю свои конфиги.
Описание документа группы
<?php
// src/Acme/StoreBundle/Document/Group.php
namespace Acme\StoreBundle\Document;
//use FOS\UserBundle\Document\Group as BaseGroup;
use Sonata\UserBundle\Document\BaseGroup as BaseGroup;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document(collection="documents")
*/
class Group extends BaseGroup
{
/**
* @MongoDB\Id(strategy="auto")
*/
protected $id;
/**
* Get id
*/
public function getId()
{
return $this->id;
}
}
Описание документа пользователя
<?php
// src/Acme/StoreBundle/Document/User.php
namespace Acme\StoreBundle\Document;
//use FOS\UserBundle\Document\User as BaseUser;
use Sonata\UserBundle\Document\BaseUser as BaseUser;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document(collection="users")
*/
class User extends BaseUser
{
/**
* @MongoDB\Id(strategy="auto")
*/
protected $id;
/**
* @MongoDB\ReferenceMany(targetDocument="Group")
*/
protected $groups;
public function __construct()
{
parent::__construct();
// your own logic
}
/**
* Get id
*/
public function getId()
{
return $this->id;
}
}
Конфиги
# app/cache/config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: config_sonata_admin.yml }
framework:
#esi: ~
#translator: { fallback: "%locale%" }
translator: ~
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
doctrine_mongodb:
connections:
default:
server: mongodb://%database_host%:%database_port%
options: {}
default_database: %database_name%
document_managers:
default:
auto_mapping: true
mappings:
AcmeStoreBundle: ~
SonataUserBundle: ~
FOSUserBundle: ~
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
# app/config/config_sonata_admin.yml
fos_user:
db_driver: mongodb
firewall_name: main
user_class: Acme\StoreBundle\Document\User
group:
group_class: Acme\StoreBundle\Document\Group
profile: # Authentication Form
form:
type: fos_user_profile
handler: fos_user.profile.form.handler.default
name: fos_user_profile_form
validation_groups: [Authentication] # Please note : this is not the default value
sonata_user:
# security_acl: false
manager_type: mongodb
class:
user: Acme\StoreBundle\Document\User
group: Acme\StoreBundle\Document\Group
profile: # Profile Form (firstname, lastname, etc ...)
form:
type: sonata_user_profile
handler: sonata.user.profile.form.handler.default
name: sonata_user_profile_form
validation_groups: [Profile]
sonata_block:
default_contexts: [admin]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
sonata.admin.block.search_result:
contexts: [admin]
sonata.block.service.text:
contexts: [admin]
sonata.user.block.menu:
contexts: [admin]
sonata.user.block.account:
contexts: [admin]
services:
sonata.user.serializer.handler.user:
class: Sonata\UserBundle\Serializer\UserSerializerHandler
tags:
- { name: jms_serializer.subscribing_handler }
arguments:
- [ sonata.user.mongodb.user_manager ]
sonata_admin:
security:
handler: sonata.admin.security.handler.role
title: Sonata Project
title_logo: /bundles/sonataadmin/logo_title.png
sonata_doctrine_mongo_db_admin:
templates:
form:
- SonataDoctrineMongoDBAdminBundle:Form:form_admin_fields.html.twig
filter:
- SonataDoctrineMongoDBAdminBundle:Form:filter_admin_fields.html.twig
types:
list:
array: SonataAdminBundle:CRUD:list_array.html.twig
boolean: SonataAdminBundle:CRUD:list_boolean.html.twig
date: SonataAdminBundle:CRUD:list_date.html.twig
time: SonataAdminBundle:CRUD:list_time.html.twig
datetime: SonataAdminBundle:CRUD:list_datetime.html.twig
text: SonataAdminBundle:CRUD:base_list_field.html.twig
trans: SonataAdminBundle:CRUD:list_trans.html.twig
string: SonataAdminBundle:CRUD:base_list_field.html.twig
smallint: SonataAdminBundle:CRUD:base_list_field.html.twig
bigint: SonataAdminBundle:CRUD:base_list_field.html.twig
integer: SonataAdminBundle:CRUD:base_list_field.html.twig
decimal: SonataAdminBundle:CRUD:base_list_field.html.twig
identifier: SonataAdminBundle:CRUD:base_list_field.html.twig
show:
array: SonataAdminBundle:CRUD:show_array.html.twig
boolean: SonataAdminBundle:CRUD:show_boolean.html.twig
date: SonataAdminBundle:CRUD:show_date.html.twig
time: SonataAdminBundle:CRUD:show_time.html.twig
datetime: SonataAdminBundle:CRUD:show_datetime.html.twig
text: SonataAdminBundle:CRUD:base_show_field.html.twig
trans: SonataAdminBundle:CRUD:show_trans.html.twig
string: SonataAdminBundle:CRUD:base_show_field.html.twig
smallint: SonataAdminBundle:CRUD:base_show_field.html.twig
bigint: SonataAdminBundle:CRUD:base_show_field.html.twig
integer: SonataAdminBundle:CRUD:base_show_field.html.twig
decimal: SonataAdminBundle:CRUD:base_show_field.html.twig
Перечень зарегистрированных бандлов
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
new Sonata\CoreBundle\SonataCoreBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new FOS\UserBundle\FOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
new Sonata\AdminBundle\SonataAdminBundle(),
new Sonata\DoctrineMongoDBAdminBundle\SonataDoctrineMongoDBAdminBundle(),
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
new Acme\StoreBundle\AcmeStoreBundle(),
);
Установленные пакеты в composer
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.5.*",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0",
"sensio/framework-extra-bundle": "~3.0",
"incenteev/composer-parameter-handler": "~2.0",
"doctrine/mongodb-odm": "1.0.*@dev",
"doctrine/mongodb-odm-bundle": "3.0.*@dev",
"friendsofsymfony/user-bundle": "~1.3@dev",
"sonata-project/user-bundle": "~2.3@dev",
"sonata-project/admin-bundle": "~2.3@dev",
"sonata-project/datagrid-bundle": "~2.2@dev",
"sonata-project/doctrine-mongodb-admin-bundle": "~2.3@dev",
"doctrine/doctrine-fixtures-bundle": "2.2.*",
"sonata-project/easy-extends-bundle": "dev-master"
},
С этими настройками у меня выскакивает следующая ошибка по маршруту
http://[ваш_домен]/login
An exception has been thrown during the rendering of a template ("No mapping found for field 'username' in class 'Acme\StoreBundle\Document\User'.") in SonataUserBundle:Security:base_login.html.twig at line 86.